Use this task to write the code needed by a session EJB or J2EE client application to manage an ActivitySession, based on the example code extract provided.
Why and when to perform this task
In most situations, an enterprise bean can depend on the EJB container to manage ActivitySessions within the bean. In these situations, all you need to do is set the appropriate ActivitySession attributes in the EJB module deployment descriptor, as described in Configuring EJB module ActivitySession deployment attributes. Further, in general, it is practical to design your enterprise beans so that all ActivitySession management is handled at the enterprise bean level.
However, in some cases you may need to have a session bean or J2EE client participate directly in ActivitySessions. You then need to write the code needed by the session bean or J2EE client application to manage its own ActivitySessions.
When preparing to write code needed by a session bean or J2EE client application to manage ActivitySessions, consider the points described in ActivitySessions and transaction contexts.
To write the code needed by a session EJB or J2EE client application to manage an ActivitySession, complete the following steps based on the example code extract below:
Steps for this task
The default timeout can also be overridden for each application server, on the server-> Activity Session Service panel of the administrative console.
Example
// Get initial context InitialContext ic = new InitialContext(); // Lookup UserActivitySession UserActivitySession uas = (UserActivitySession)ic.lookup("java:comp/websphere/UserActivitySession"); // Set the ActivitySession timeout to 60 seconds uas.setSessionTimeout(60); // Start a new ActivitySession context uas.beginSession(); // Do some work under this context MyBeanA beanA.doSomething(); ... MyBeanB beanB.doSomethingElse(); // End the context uas.endSession(EndModeCheckpoint);
Related concepts
The ActivitySession service
Related tasks
Developing a J2EE application to use an ActivitySession