Delegated Thread Creation in a J2EE Web Application
Original Publication Date: 2004-Jun-10
Included in the Prior Art Database: 2004-Jun-10
This disclosure descries a technique for delegating thread creation to avoid the inherent problems in J2EE with creating threads directly. This is done by creating a Runnable object that is not started until a new servlet request arrives. The purpose of the new servlet request is to start the execution of the Runnable after the user interface has been updated.
Delegated Thread Creation in a J 2EE Web Application
Java Threads are an extremely valuable tool for J2EE Web applications because they provide the framework needed for multi-tasking. Progress inidication, for example, is an important feature that would not be possible without Threads. This is because one Thread is needed to perform the work while another Thread monitors the work and displays feedback to the user. However, the current J2EE web technology imposes a significant barrier to multi-tasking because it does not provide a way to create Threads that can outlive the span of an HTTP request/response cycle. Here is an excerpt from the Java
2.4 Servlet Specification that describes the limitation :
Implementations of the request and response objects are not guaranteed to be thread safe. This means that they should only be used within the scope of the request handling thread. References to the request and response objects should not be given to objects executing in other threads as the resulting behavior may be nondeterministic. If the thread created by the application uses the container-managed objects, such as the request or response object, those objects must be accessed only within the servlet's service life cycle and such thread itself should have a life cycle within the life cycle of the servlet's service method because accessing those objects after the service method ends may cause undeterministic problems.
Java 2.4 Servlet Specification http://jcp.org/aboutJava/communityprocess/final/jsr154/index.html
Figure 1 below shows a graphical depiction of the Threading limitation.
While this limitation does not specifically prohibit the creation of Threads in...