concept service provider in category java

This is an excerpt from Manning's book The Java Module System.
In the previous section, you used the computed universe to list all modules referenced, thus effectively printing all transitive dependencies of some module. That isn’t the only use case for
--limit-modules, though. More will come up when we discuss services in chapter 10 (see section 10.1.2 on limiting service providers).
Figure 10.7 With
--limit-modules monitor, the universe of observable modules is limited to monitor's transitive dependencies, which excludes the service providers resolved in figure 10.6.![]()
A service provider must be public, but there’s no technical requirement for exporting its package—the service loader is fine with instantiating inaccessible classes. Thus, exporting the package containing a provider needlessly enlarges a module’s API surface. It also invites consumers to do things they’re not supposed to, like casting a service to its real type to access additional features (analogous to what happened with
URLClassLoader; see section 6.2.1). I hence advise you to not make service providers accessible.