Java Reference
In-Depth Information
■
as an option, task classes can implement the
javax.enterprise.concurrent.ManagedTask
interface. task
classes that implement this interface provide identity information and execution properties. implementations of the
Managedtask interface can also register a
javax.enterprise.concurrent.ManagedTaskListener
instance to receive
lifecycle events notifications.
Note
Creating Application Server Concurrent Resources
In Java EE 7, the
ManagedExecutorService
was introduced, adding the ability to produce asynchronous tasks that are
managed by an application server. Application server administrators can create
ManagedExecutorService
resources
within an application server that can be utilized by one or more applications, much like a Java Message Service (JMS)
Topic
or
Queue
. There are a couple of ways to create application server concurrent resources. You can utilize the
GlassFish command line
asadmin
utility. Alternatively, the GlassFish administration console has been enhanced with
new forms for concurrent resource management for those who prefer working in a GUI. First, let's take a look at how
to utilize the
asadmin
utility for creation of the resources.
To create a service, issue
the asadmin create-managed-executor-service
command at the command prompt,
passing the name that you would like to use to identify the service. There are a bevy of options that can be used to
customize the service in different ways. For instance, the service can be configured to let tasks run for a specified
amount of time, thread pools can be configured, etc., allowing one to generate a
ManagedExecutorService
that will
best suit the application requirements. To utilize concurrent utilities such as reporter tasks, the application server
must be configured to utilize a
ManagedExecutorService
. To create a
ManagedExecutor
Service in GlassFish, run the
following command at the command prompt:
<path-to-glassfish>/bin/asadmin create-managed-executor-service concurrent/BatchExecutor
In the preceding command-line action, the name of the
ManagedExecutorService
that is being created is
concurrent/BatchExecutor
. However, this could be changed to better suit the application; the service can be named
with any valid String. To see all of the options available for the
create-managed-executor-service command
, issue the
--help
flag. The following shows the results of doing so:
bin/asadmin create-managed-executor-service --help
NAME
create-managed-executor-service
SYNOPSIS
Usage: create-managed-executor-service [--enabled=true] [--c
ontextinfo=contextinfo] [--threadpriority=5] [--longrunningt
asks=false] [--hungafterseconds=hungafterseconds] [--corepoo
lsize=0] [--maximumpoolsize=2147483647] [--keepaliveseconds=
60] [--threadlifetimeseconds=0] [--taskqueuecapacity=2147483
647] [--description=description] [--property=property] [--ta
rget=target] jndi_name