Find service in a layer with multiple classloaders

Alex Orlov ooo_saturn7 at mail.ru
Fri Dec 4 14:20:02 UTC 2020


Hello all,
 
I have a layer with many class loaders (created using public static ModuleLayer.Controller defineModulesWithManyLoaders​(Configuration cf,  List<ModuleLayer> parentLayers, ClassLoader parentLoader)).
 
Let’s suppose we have there three modules (a,b,c). One of the module provides FooService. As I understand to find AService in this layer we can use class loader of ANY module in this layer (any of a,b,c). For example
 
ServiceLoader.load(FooService.class, layer.modules().stream().findAny().get().getClassLoader());
 
Could anyone say if this statement and this code are correct or not?
 
--
Best regards, Alex Orlov


More information about the jigsaw-dev mailing list