Using concurrency utilities in Java EE
In Java EE 6 (specifically in the EJB container), creation of new threads was discouraged
because the application server would not be able to control the stability of the platform nor
guarantee any transactional features. This could be a problem for applications that would
like to effectively use CPU and execute multiple tasks in parallel. It was possible to over-
come this using JCA adapters, but additional effort was required to implement them.
Fortunately, the JSR 236 introduces the ManagedExecutorService (along with the
ManagedScheduledExecutorService ), a container-aware version of the Ex-
ecutorService used in Java SE. The well-known API ported to Java EE was merged in
the platform, providing a smooth workflow for concurrent operations in the EJB container.
The new managed executor services have the following advantages over the standard ones:
• They rely on the thread pool provided by the container. This means that the server
controls have many threads that can be spawned from all deployed applications
and you can tweak the configuration in order to ensure the desired quality of ser-
• The thread configuration is totally separated from the code, so it is possible to
change it without changing the application itself.
• It is possible to propagate the caller context to the created thread. For example, it is
possible to use the security principal of the user's request that initiated the new
• The application server allows monitoring of the current thread count.
• Threads started by the managed executors can create new transactions for business
components; they cannot, however, participate in transactions from other compon-
The main parts of the concurrency utilities are described in the following table:
This is used to execute submitted tasks in an asynchronous manner. The developer may submit
a Callable or Runnable function and use returned Future to check for the result when it
is available. The container context will be propagated by the container.
This interface extends the standard ExecutorService interface.
ManagedScheduledExecutorService This is similar to ManagedExecutorService , but it is used to execute tasks at specific
times (cyclic, scheduled, or delayed).
Search WWH ::