Java Reference
In-Depth Information
offers four main programming interfaces whose instances must be made available to
application components as container-managed objects. The offered interfaces are:
ContextService
,
ManagedExecutorService
,
ManagedScheduledExecut-
orService
, and
ManagedThreadFactory
. All these interfaces are contained in
the
javax.enterprise.concurrent
package.
These four interfaces can be explained as follows:
•
Managed executor service
: The
ManagedExecutorService
interface
extends the
java.util.concurrent.ExecutorService
interface. It al-
lows us to submit an asynchronous task that will be run on a separate thread
created and managed by the container. By default, any Java EE 7-compliant
server must provide a
ManagedScheduledExecutorService
that can be
accessed by application components under the
JNDI
name
java:comp/
DefaultManagedScheduledExecutorService
. But, if you want to cre-
ate your own, you must first declare the
ManagedExecutorService
re-
source environment reference in the
web.xml
file for a web application or
ejb-jar.xml
for an EJB module. The specification recommends that all
ManagedExecutorService
resource environment references be organ-
ized in the
java:comp/env/concurrent
subcontext.
• The following configuration is an example declaration of a
Man-
agedExecutorService
resource environment reference:
<resource-env-ref>
<resource-env-ref-name>
concurrent/
ReportGenerator
</resource-env-ref-name>
<resource-env-ref-type>
javax.enterprise.concurrent.ManagedExecutorService
</resource-env-ref-type>
</resource-env-ref>