You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am studing for 1Z0-815 and I am trying to understand ServiceLoader. Honestly, I haven't use it yet in real scenarios. I was reading https://www.infoq.com/articles/java11-aware-service-module/ and I was really getting the point until I reached:
..." So far so good, but when we start to implement a full-blown system using this new services mechanism, we will soon realize that we have to write boilerplate code each time we need to locate and load a service. It gets more tedious and a tad more complex when we have to run some initialization logic each time we load a service provider.
A typical thing to do is to refactor the boilerplate code into a utility class and add it as part of a common module shared by other modules in our application. While that’s a good first step, due to the strong encapsulation and reliable configuration guarantees provided by the Java module system, our utility method will fail to use the ServiceLoader class and load services.
Since the common module has no knowledge of the given service interface and since it doesn’t include the “uses” clause in its module descriptor, the ServiceLoader cannot locate providers that implement the service interface even though they might be present on the module path. Not only that, but if you add the “uses” clause to the common module descriptor, it defeats the purpose of encapsulation and worse, introduces circular dependency...."
As far as I understood, Susel was mainly created to avoid "utility method will fail to use the ServiceLoader class and load services." when we code a common module vecause "ServiceLoader cannot locate providers that implement the service interface". Now I really got confused. Kindly, can you exemplify? It wouldn't be easily fix by "include the “uses” clause in its module descriptor"?
The text was updated successfully, but these errors were encountered:
I am studing for 1Z0-815 and I am trying to understand ServiceLoader. Honestly, I haven't use it yet in real scenarios. I was reading https://www.infoq.com/articles/java11-aware-service-module/ and I was really getting the point until I reached:
..." So far so good, but when we start to implement a full-blown system using this new services mechanism, we will soon realize that we have to write boilerplate code each time we need to locate and load a service. It gets more tedious and a tad more complex when we have to run some initialization logic each time we load a service provider.
A typical thing to do is to refactor the boilerplate code into a utility class and add it as part of a common module shared by other modules in our application. While that’s a good first step, due to the strong encapsulation and reliable configuration guarantees provided by the Java module system, our utility method will fail to use the ServiceLoader class and load services.
Since the common module has no knowledge of the given service interface and since it doesn’t include the “uses” clause in its module descriptor, the ServiceLoader cannot locate providers that implement the service interface even though they might be present on the module path. Not only that, but if you add the “uses” clause to the common module descriptor, it defeats the purpose of encapsulation and worse, introduces circular dependency...."
As far as I understood, Susel was mainly created to avoid "utility method will fail to use the ServiceLoader class and load services." when we code a common module vecause "ServiceLoader cannot locate providers that implement the service interface". Now I really got confused. Kindly, can you exemplify? It wouldn't be easily fix by "include the “uses” clause in its module descriptor"?
The text was updated successfully, but these errors were encountered: