Make delicious recipes!

Service Loader



ServiceLoader in java is used to load all the implementations corresponding to a service.
Following definitions hold true for the above statement:
Service : A set of interfaces or abstract classes.

Service Provider: Classes that provide an implementation of a Service. 
   A service provider class must have a zero-argument constructor so that it can be instantiated by reflection.
   A service provider is identified by placing a provider-configuration 
   file in the resource directory META-INF/services. 
   The file's name is the fully-qualified binary name of the service's type and 
   it contains a list of fully-qualified binary names of concrete provider classes, one per line.

Service Loader: A loader loads all the providers(implementations) for a service(interface/abstract-class).
  It locates the providers from the META-INF/services/<fully-qualified-interface-name>
  The providers are instantiated using their no-args constructors.
  After loading, the ServiceLoader maintains a list of all the provider objects.
  Application needs to iterate through this list and select the one most suitable for their needs.







Like us on Facebook to remain in touch
with the latest in technology and tutorials!


Got a thought to share or found a
bug in the code?
We'd love to hear from you:

Name:
Email: (Your email is not shared with anybody)
Comment:

Facebook comments:

Site Owner: Sachin Goyal