JBoss.org Community Documentation

4.3. Shutting down JBoss DNA services

The JBoss DNA services are utilizing resources and threads that must be released your application is ready to shut down. The safe way to do this is to simply obtain the ServiceAdministrator for each service (via the getServiceAdministrator() method) and call shutdown(). As previously mentioned, the shutdown method will simply prevent new work from being process and will not wait for existing work to be completed. If you want to wait until the service completes all its work, you must wait until the service terminates. Here's an example that shows how this is done:

// Shut down the service and wait until it's all shut down ...
sequencingService.getAdministrator().awaitTermination(5, TimeUnit.SECONDS);

// Shut down the observation service ...
observationService.getAdministrator().awaitTermination(5, TimeUnit.SECONDS);

At this point, we've covered how to configure and use the JBoss DNA services in your application. The next chapter goes back to the sample application to show how all these pieces fit together.