Introduction
The IBM WebSphere application Server software provides the following two mechanisms to support the safe use of threads in Servlet and EJB components by j2ee™ application developers:
Asynchronous Bean
Commonj Timer and Workmanager for application Servers 1.1 specification.
Both programming modes allow you to create pool and daemon threads to run the Java business logic.
In both programming modes, threads can be reused by different applications. When the application logic starts and terminates, this can be done by applying and deleting the Java context information inside and outside the thread. Therefore, a single thread pool can be used by multiple applications. Each time a thread is used, its identity changes.
Each time you reuse a thread, you must make the context of the thread more specific, and for applications that may rarely perform activities on those threads, the overhead will be particularly high. In these cases, a component-scoped thread pool is required and has a fixed Java EE context on each thread. This can be done by using the asynchronous Beans EventSource interface.
This article describes how to use the asynchronous Beans EventSource to construct a thread factory, which includes a downloadable example called a concurrency adapter (Concurrent Adapter) that can be used with a third-party thread pool implementation to create the ability to A fast thread pool that works on a WebSphere application Server.
Global thread pool
WebSphere application Server delivers high-performance and highly scalable thread pooling implementations. Asynchronous Bean and Commonj Workmanager Use this thread pool for all pool threads.
Because the Workmanager instance can be used for global namespaces, they can be shared across multiple applications, so you need Java context switching. To complete this task, Workmanager takes a snapshot of the Java context on the thread when submitting work. The resulting object becomes the Workwithexecutioncontext (WWEC) object (Figure 1).
Figure 1. Workwithexecutioncontext
If you use Workmanager as the global thread pool (Figure 2), each task that is submitted to the thread pool will have an application context that is applied to the thread (or removed from the thread) each time you assign work to the thread:
Submit work to Workmanager thread pool (blue box)
Gets a snapshot of the Java application context and stores it as a WWEC object with the work.
Add WWEC to the pool's input queue.
The worker thread extracts a WWEC from the input queue and runs it.
Gets a snapshot of the current Java-EE application context on the worker thread to recover after the work completes.
Applies the Java EE context stored with WWEC to the thread.
Run the job.