Thanks, Alan. That sounds promising. I'll try it.

> -----Original Message-----
> From: Alan Bateman [mailto:alan.bate...@oracle.com]
> Sent: Montag, 20. Februar 2017 20:49
> To: Langer, Christoph <christoph.lan...@sap.com>; jigsaw-
> d...@openjdk.java.net
> Subject: Re: Another module system question
> 
> On 20/02/2017 19:15, Langer, Christoph wrote:
> 
> > :
> >
> > However, the main issue I have with this approach is: When is the time that
> my service from the second module 'b' will be available and registered? I
> assume, module 'a' will load first, then 'b'. So, when I use some static class
> initialization as the place in 'a' where I try to load the service from 'b', 
> I guess
> the service couldn't be available yet. Is there some module system
> initialization hook, where I could plug in and then assume the service from 
> 'b'
> is ready? Or should I maybe add a static class initializer in 'a' which would 
> try
> to resolve the implementing service from 'b' in a loop until it is ready?
> >
> Declaring the `uses` and `provides` and deploy the modules on the module
> path should be enough. When the consumer module (the module with
> `uses`)
> is resolved then it will trigger any providers to be resolved. The
> resolved modules are loaded eagerly (meaning they are defined to the VM)
> but there is nothing actually loaded. When you invoke ServiceLoader to
> get a stream or to iterate over the providers then it will load the
> provider from `b`. It's probably best to just try it out as it's easy to
> get something working. Often the hard bit is deciding on the service
> interface and choosing the methods to expose to allow a consumer select.
> 
> -Alan

Reply via email to