See: Description
| Interface | Description |
|---|---|
| Service |
Interface for services.
|
| ServiceListener | |
| ServiceMBean |
MBean interface for all
Service implementations. |
| Class | Description |
|---|---|
| AbstractService | |
| ServiceListenerManager |
Listener manager for
ServiceListeners. |
| State |
Using a Service is pretty straight-forward:
Service someService = new SomeService(); someService.init(); someService.setParameter1(...); someService.setParameter2(...); // some more preparations // and finally... someService.start();
If you want to implement your own service it is recommended that you override
the AbstractService base class as it takes care
of a couple of things for you, like creating the thread that runs your
service, managing the Service.stop() method,
providing synchronized access to state variables, and other things.
The AbstractService base class adds a
service method for each of the
Service.init(),
Service.start(),
Service.stop(), and
Service.destroy() methods that let you take care
of things in your own service without having to interfere with the stuff at
AbstractService does for you. The
AbstractService.serviceRun() method is the place
to implement your magic then. It should be designed as an infinite loop like
this:
protected void serviceRun() {
while (!shouldStop()) {
doStuff();
doLengthyStuff();
if (shouldStop()) {
continue;
}
doMoreLengthyStuff();
}
}
Checking the AbstractService.shouldStop() every
once in a while ensures that your service stops within a short time after
Service.stop() has been called.Copyright © 2026. All rights reserved.