Callable and Runnable tasks
In Concurrency Utilities for Java EE, a Callable or Runnable task is used by application components to run code in parallel with the Java EE context of the submitting thread.
A task implements the java.util.concurrent.Callable interface or the java.lang.Runnable interface.
A component wanting to run work in parallel locates a managed executor in JNDI, then calls a submit, schedule, invoke, or execute method using the Callable or Runnable task as a parameter.
The submit and schedule methods return a Future or ScheduledFuture. The Future is a handle that provides a link from the component to the now running task. The Future is typically used when the component needs to obtain the result or status of a task, or to wait for one or more of its running tasks to complete. The invokeAll method takes a list of tasks that the component wants to wait on. A timeout can be specified, which prevents the component from waiting indefinitely.
By submitting tasks to a managed executor, the application can use threads that are affiliated with the Java EE environment and managed by the application server. In addition, these threads have Java EE context (for example, a java:comp) and are authenticated when they fire.
Developing tasks to run code in parallel