03 April 2008

Java SE 6 ServiceLoader

Today I had a look at the ServiceLoader class in Java SE 6.

The ServiceLoader is a generic factory that can be configured with a simple file located in META-INF/services. The filename must be the full qualified name of the interface and contains a single line with the full qualified name of the implementation ch.simas.impl.MyServiceImpl.

The usage is also very simple:
ServiceLoader loader = ServiceLoader.load(MyService.class);

for (Iterator it = loader.iterator(); it.hasNext();) {
MyService myService = it.next();

Try it out!

Keine Kommentare: