ServiceLoader.load* take 2

Jesse Glick jesse.glick at oracle.com
Tue Jun 12 14:42:51 PDT 2012


On 06/12/2012 05:34 PM, David M. Lloyd wrote:
> Is there an expectation that a configuration will exist per-application

Yes, I think that is the intent.

> so that applications do not tend to have overlapping modules?

They could certainly overlap in contained modules, but a given JVM (or isolate??) would be running one configuration with a particular set of modules in it, according to 
the application's needs.

> Does this mean that [...] service implementations should generally be global per installation?

No, I think just global per _application_. In other words, given a service

package api;
public interface ImageFileReader {
   boolean supports(Path image);
   Image read(Path image) throws IOException;
}

you would expect that any module in a given application calling

for (ImageFileReader r : ServiceLoader.load(ImageFileReader.class)) {...}

would get the same list of services. This would be true in classpath mode simply because the TCCL is always going to be ClassLoader.getSystemClassLoader(), i.e. JARs 
dumped in the -classpath.



More information about the jigsaw-dev mailing list