5.3.8 Precautions When Implementing
This subsection describes the settings and precautions when implementing the method timeout functionality and method cancellation functionality.
- Organization of this subsection
(1) Setting the timeout value in the processing of the Web application requests
In the processing of the Web application requests, you can specify timeout values for the methods listed in the following table. For the range of the timeout values for each method, see 5.3.5 Example of setting timeout value and the range of setting values.
Define the servlets and JSPs that uses timeout in the <servlet> tag of DD (web.xml).
When the servlet is implemented as a sub class of the javax.servlet.http.HttpServlet class and the doXXX method (doGet method or doPost method) invoked from the service method of the javax.servlet.http.HttpServlet class is overridden, a timeout is applicable to the overridden doXXX method.
The JSP service method indicates the service method of the class where the javax.servlet.jsp.JspPage interface generated from JSP is implemented.
The _jspService method defined in JSP is executed with the JspPage service method extension from the implementation class of the JspPage interface. If JspPage is not specified in JSP, the implementation class of the JspPage interface provided by the Web container is used.
(2) Setting the timeout value in the method invocation process of the Enterprise Bean
In the method invocation process of the Enterprise Bean, you can specify the timeout value for each method. You cannot specify the timeout value for each Enterprise Bean.
Table 5-13 lists the methods to which method timeout is applied in the methods for invoking the J2EE applications, and Table 5-14 lists the methods to which method timeout is applied in the callback methods implemented in the J2EE application.
As in the case of the find method, the select method in CMP2.0, and the find method in CMP1.0, the method timeout is not applied to the methods that are not implemented in Java programs. Also, the method timeout is not applied to the callback methods (such as ejbActivate or ejbLoad) that determine whether to call a method depending on the status when the method was invoked.
- Legend:
-
Y: Applied.
N: Not applied.
A: A method timeout is applied, but method cancellation is not applied.
--: Not applicable.
- Legend:
-
Y: Applied
N: Not applied
A: A method timeout is applied, but method cancellation is not applied.
--: Not applicable
- #
-
Method timeout is not applied when the method is invoked by the container processes such as the timeout functionality.
(3) Option message settings when the method timeout occurs
When method timeout occurs, you can add an optional character string in the detailed part of the message that notifies the timeout by setting an option in advance. The following is the execution example.
// User processing ... // Addition of a message RequestMonitorMessage.setMessage("Add a message."); ... // User processing
You cannot use this method in applications that are not monitored such as the followings:
-
EJB client applications
-
Applications operating in threads generated and started by J2EE applications
(4) Precautions during application development using method cancellation
When using method cancellation, you must be careful about the data structure of the application when you develop the application.
If you execute method cancellation, the execution of the thread is interrupted at an unexpected location. As a result, you must not use method cancellation for an application with the shared data that is updated or deleted using the threads other than the threads targeted for method cancellation. The shared data is destroyed and might affect the processing of other requests.
For example, suppose a shared area (variables A=1, B=2) is set for an Enterprise Bean and is accessed by multiple threads (thread 1 and thread 2), if the ThreadDeath exception occurs while thread 1 is updating (A=10, B=20) the shared area, thread 1 will end with the half-finished (A=10, B=2) update. At this time, if thread 1 references the half-updated data with thread 2 and calculates A*B, the result of the calculation will be invalid (Right: 200, Wrong: 20). As a result, you cannot use method cancellation in such examples.
Furthermore, if the optimize local invocation functionality is used, you must check that the data has such a structure so that the update and delete operations are executed using multiple threads within or across applications.