Java EE 7 SDK

Samples Main Page

# The Executor Concurrency Sample Application

This sample demonstrates how to use `javax.enterprise.concurrent.ManagedExecutorService` for submitting tasks.

## Description

The demo contains a collection of servlets that show how to use methods from the `ManagedExecutorService` interface to submit tasks to be processed asynchronously.

All the sample servlets in this demo use the default `ManagedExecutorService` as defined in the Concurrency Utilities for Java EE 1.0 specification which is available in all compliant Java EE Products. Thus no special configuration is required.

The following is a list of servlets included in this demo:

URI pattern | Description
--- | ---
/TestResourceServlet | Submit tasks using a `ManagedExecutorService` retrieved using `@Resource` in a servlet, using the `execute()` and `submit()` methods.
/TestJNDIServlet | Submit tasks using a `ManagedExecutorService` retrieved using JNDI lookup in a servlet, using the `execute()` and `submit()` methods.
/TestEJBServlet | Submit tasks using a `ManagedExecutorService` in an EJB session bean, using the `sumbit()` method.
/TestInvokeAllServlet | Submit a collection of tasks using the `invokeAll()` method in `ManagedExecutorService`, and wait for all tasks to complete.
/TestInvokeAnyServlet | Submit a collection of tasks using the `invokeAny()` method in `ManagedExecutorService`, and wait for the first task to complete.
/TestListenerServlet | Submit a `ManagedTask` with a `ManagedTaskListener` to receive task lifecycle callbacks.
/TestTransactionServlet | Submit tasks that make use of `javax.transaction.UserTransaction`.

The application is built and deployed as a WAR file.

## Key Features

- Lookup of `ManagedExecutorService` from servlets and EJBs
- Use of the `submit()`, `execute()`, `invokeAll()`, `invokeAny()` methods in `ManagedExecutorService`
- Use of `ManagedTaskListener` to receive task lifecycle notifications
- Perform JNDI lookup from a task
- Transaction demarcation using `javax.transaction.UserTransaction` from a task

## Building, Deploying, and Running the Application

Perform the following steps to build, deploy, and run the application:

1. Set up your build environment and configure the application server with which the build system has to work by following the common build instructions.
2. `samples_install_dir` is the sample application base directory. Go to: `samples_install_dir/javaee7/concurrency/executor`.
3. Build, deploy, and run the sample application using the `run` outcome.

   `mvn clean verify cargo:run`

4. The front page of this sample is at `http://localhost:8080/executor`
   (the port number might vary).
5. Use the `clean` outcome to undeploy the sample application and to remove the temporary directories such as `build` and `dist`.

   `mvn clean`

## Troubleshooting

If you have problems when running the application, refer to the troubleshooting document.

Copyright © 1997-2013 Oracle and/or its affiliates. All rights reserved.