Services and Bindings - expected usage scenarios
Alan Bateman
Alan.Bateman at oracle.com
Tue Nov 29 12:06:28 UTC 2016
On 29/11/2016 11:35, Pisarev, Vitaliy wrote:
> Another best practices question.
>
> I am aware that the ServiceLoader API is not new to Java. What's new in Java 9 is that is has been put forward to the front of the stage and it is now very easy
> for a service provider to register a service.
>
> The thing is that up until now, the ServiceLoader was a relatively low level component, primarily used by infrastructure components that loaded plugins that implemented various java specs.
> It is no surprise than that the ServiceLoader is something that very few ever heard of.
>
> Is it the intent of project Jigsaw that the service loader becomes a central and ubiquitous mechanism in the day to day work of plain old java developers?
> As far as I am concerned, it is a very useful tool even when I do not have a plugin architecture and just want a module to expose a certain service via an interface without having to jump throw hooks
> in order to provide the consumer a way to instantiate it..
>
> Which leads me to the next question: is the returned instance a singleton or a prototype?
Services are a first class part of the module system but are a somewhat
advanced topic. The ServiceLoader API is part of the story but arguably
just a small aspect when compared to the architectural and design issues
involved in moving to services, loose coupling, and improved SoC.
Provider factories can implement singletons where needed, the details
are in the javadoc [1].
-Alan
[1] http://download.java.net/java/jigsaw/docs/api/index.html
More information about the jigsaw-dev
mailing list