Hitachi

uCosminexus Application Server Operation, Monitoring, and Linkage Guide


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).

Table 5‒12: Targets applicable for method timeout (Processing of the Web application requests)

Case

Method

Conditions

Servlets or JSPs

service

No conditions.

init

Method timeout is applied to servlets (JSP when JSP is used) where the <load-on-startup> tag is not defined in DD(web.xml), only when the method timeout is executed for the initial request.

destroy

Method timeout is applied only when the method throws javax.servlet.UnavailableException. This exception indicates that the servlet is permanently unavailable when the service method is invoked.

Filter

doFilter

No conditions.

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.

Table 5‒13: Targets applicable for method timeout (Enterprise Bean invocation)

Interface

Method

Stateless

Session

Bean

Stateful

Session

Bean

Singleton

Session

Bean

Entity

Bean

(BMP)

Entity

Bean

(CMP2.0)

Entity

Bean

(CMP1.1)

Message

-driven

Bean

Home interface

create

N

Y

--

Y

Y

Y

N

finder

--

--

--

Y

N

N

--

select

--

--

--

--

N

--

--

home

--

--

--

Y

Y

--

--

Component interface

remove

N

Y

--

Y

Y

Y

N

Business method

Y

Y

--

Y

Y

Y

--

Business interface

Business method

Y

Y

A

--

--

--

--

Business method (asynchronous)

A

N

A

--

--

--

--

javax.jms.MessageListener

onMessage

--

--

--

--

--

--

Y

Any message listener interface (EJB 2.1 or later)

Any message listener method

--

--

--

--

--

--

Y

Legend:

Y: Applied.

N: Not applied.

A: A method timeout is applied, but method cancellation is not applied.

--: Not applicable.

Table 5‒14: Targets applicable for method timeout (Callback method)

Method

Stateless

Session

Bean

Stateful

Session

Bean

Singleton

Session

Bean

Entity

Bean

(BMP)

Entity

Bean

(CMP2.0)

Entity

Bean

(CMP1.1)

Message

-driven

Bean

Constructor

N

N

N

N

N

N

N

setSessionContext/setEntityContext/setMessageDrivenContext

N

N

N

N

N

N

N

unsetSessionContext/unsetEntityContext

N

N

N

N

N

N

--

ejbCreate<Method>

N

Y

--

Y

Y

Y

N

ejbPostCreate<Method>

--

--

--

N

N

N

--

ejbRemove#

N

Y

--

Y

Y

Y

N

ejbActivate

N

N

--

N

N

N

--

ejbPassivate

N

N

--

N

N

N

--

ejbLoad

--

--

--

N

N

N

--

ejbStore

--

--

--

N

N

N

--

ejbfind<Method>

--

--

--

Y

--

--

--

ejbSelect<Method>

--

--

--

--

--

--

--

@PostConstruct

N

Y

A

--

--

--

--

@PreDestroy

N

Y

A

--

--

--

--

home method

--

--

--

Y

Y

--

--

Business method

Y

Y

A

Y

Y

Y

--

onMessage

--

--

--

--

--

--

Y

Any message listener method (EJB 2.1 or later)

--

--

--

--

--

--

Y

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:

(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.