Java Reference
In-Depth Information
Once you have successfully navigated to the panel, click on the “New” button to open the “New Managed
Scheduled Executor Service” panel (Figure 11-4 ). Within this panel, you must specify a JNDI name for the resource,
along with a number of optional parameters, including context settings, thread priority, and thread pool settings.
Figure 11-4. New Managed Scheduled Executor Service Panel
However, it is not necessary to generate your own ManagedScheduledExecutorService because GlassFish, and,
any Java EE 7 compliant application server, should contain a default ManagedScheduledExecutorService . To enable
an application to access the service, XML configuration within the web.xml deployment descriptor can be used, or a
@Resource annotation can be used to inject the resource. In the example below, both techniques are demonstrated.
However, in the class that is used to initiate the example task, the @Resource annotation is used to inject the
application server's default ManagedScheduledExecutorService that can be identified by the name of
concurrent/__defaultManagedScheduledExecutorService .
@Resource(name=" concurrent/__defaultManagedScheduledExecutorService ")
ManagedScheduledExecutorService mes;
To schedule the task, create an instance of the task class, and then pass the instance to one of the
ManagedScheduledExecutorService scheduler methods that are made available via the ScheduleExecutorService
interface. The methods that can be used to schedule tasks are shown in Table 11-1 .
Search WWH ::

Custom Search