Class ManagedExecutorService

java.lang.Object
org.refcodes.controlflow.ManagedExecutorService
All Implemented Interfaces:
Executor, ExecutorService

public class ManagedExecutorService extends Object implements ExecutorService
Usually ExecutorService instances originating from an application server are wrapped with this ManagedExecutorService.

The ManagedExecutorService wraps an ExecutorService and prevents execution of the ExecutorService.shutdown() and ExecutorService.shutdownNow() methods (them methods are not delegated and therewith disabled).

This is helpful when you either expect an ExecutorService passed by an application server or, if none is passed, you retrieve a private ExecutorService yourself:

In the second case, you might want to shutdown your ExecutorService after usage, in the first case you do not want to do so as the application server is to take care on shutdown. You then do not wrap your private ExecutorService; you do wrap any ExecutorService being passed to you (by an application server).

Wrapping the ExecutorService being passed from the application server and not wrapping the one you create yourself will enable you to shutdown the ExecutorService in any case; in case it is your private one, it will be shutdown; in case it is the one from the application server, the shutdown calls are just ignored.