|
Education won't help those who are proudly and willfully ignorant. They'll literally rather die before changing.
Stephan van Hulst wrote:How did you relate ServiceLoader to the Cloud?
Tim Holloway wrote:If anything, I'd say serviceloader is more oriented towards local use than cloud use, although that depends on what kind of classloader you use with it.
One is for image services and the other for database persistence services (locating a driver for a JDBC URL type such as "jdbc:mysql").
Stephan van Hulst wrote:You can use it to build plugin systems where you can load classes into your application that weren't available at compilation time.
Paul Clapham wrote:When Java was extended by classes which could process XML, the Java people threw in some code which could parse XML so that those classes would be useful. But they wrote that code so that it used a service loader to load an XML parser from the classpath. This enabled people to write better XML parsers which could easily be used by people who needed better XML parsing. And when I say "easily" that means you could just take the (properly configured) jar and add it to your classpath and you were ready to go.
Stephan van Hulst wrote:
ServiceLoader is a class that dynamically loads instances of service provider interfaces. You can use it to build plugin systems where you can load classes into your application that weren't available at compilation time.
.Anil Philip wrote: But couldn't you always do this? just switch out the jar files on the class path to get a new "provider". Unless I am mistaken, I don't know how this is new.
Education won't help those who are proudly and willfully ignorant. They'll literally rather die before changing.
Anil Philip wrote:But couldn't you always do this? just switch out the jar files on the class path to get a new "provider". Unless I am mistaken, I don't know how this is new.
Tim Holloway wrote:
You may be confusing Service Loader with Inversion of Control (IoC) mechanisms such as Spring.
Stephan van Hulst wrote:I think you're talking about swapping out JARs and rerunning the application so it uses the new JAR. Sure, as long as the JARs are binary compatible, this was always an option.
That's not the benefit that ServiceLoader brings though. There are two advantages of ServiceLoader that currrently spring to my mind:
First, ServiceLoader doesn't require the classes to be available at link-time. Instead, your application could already be running, then you drop a JAR in some plugin directory and you could hot-load it into your running application.
Secondly, ServiceLoader can load multiple different services that implement the same interface. Your application can simply iterate over all loaded services, and choose which ones it wants to call.
Education won't help those who are proudly and willfully ignorant. They'll literally rather die before changing.
The City calls upon her steadfast protectors. Now for a tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
|