ManagedJobExecutor
Integration into application servers without a resource-aware implementation is offered by a specific type ofJobExecutor called the ManagedJobExecutor. The purpose of the ManagedJobExecutor is to ensure that job execution within the process engine is correctly controlled by the application server, by using managed resources (primarily: managed threads).
In order to facilitate the ManagedJobExecutor, the engine must be configured to use it. For instance, when bootstrapping the engine from Java code, you would create a new instance of the ManagedJobExecutor and provide the resource dependency it has by injecting it from your application server’s environment. The ManagedJobExecutor can then be set as the JobExecutor that the process engine should use.
Example usage
The following code listing shows the essential configuration performed.Unmanaged resourcesThe example above injects a container managed resource, the
ManagedExecutorService, into an object for which the lifecycle is not controlled by the application server (the ManagedJobExecutor which is instantiated with its constructor). This is not a generally recommended practice, because the dependencies that are injected may become unavailable.In this use case however, this approach is chosen because the ManagedJobExecutor relies on the existence of the ManagedExecutorService and this interface was only introduced with JEE7. Earlier versions of JEE could not fulfill this dependency and would fault if the component was activated automatically for all application servers.In order to avoid that the job executor is running on unavailable resources, we recommend to shutdown the job executor via its shutdown() method when the ManagedExecutorService becomes unavailable.