Use the TaskNameManager interface

 

Overview

We can declaratively configure container managed tasks for Java 2 platform, Enterprise Edition (J2EE) web components, application clients, and EJB. On rare occasions, you might find it necessary to programmatically set the current task name. Application profiling supports this requirement with a simple interface that enables both overriding of the current task associated with the thread of execution, and resetting of the current task with the original task. Except for J2EE 1.3 applications that are executing on a server where the 5.x Compatibility Mode attribute is selected, this interface cannot be used within Enterprise JavaBeans that are configured for container-managed transactions or container-managed ActivitySessions because units of work can only be associated with a task at the exact time that the unit of work is initiated. The call to set the task name must therefore be invoked before the unit of work is begun. Units of work cannot be named after they are begun. Calls on this interface during the execution of a container-managed unit of work are simply ignored.

Application profiling does not support queries of the task that is in operation at run time. Instead, applications interact with logical task names that are declaratively configured as application managed tasks. Logical references enable the actual task name to be changed without having to recompile applications.

Wherever possible, avoid setting tasks programmatically. The declarative method results in more portable function that can be easily adjusted without requiring redevelopment and recompilation.

Note: If you select the 5.x Compatibility Mode attribute on the Application Profile Service's console page, then tasks configured on J2EE 1.3 applications are not necessarily associated with units of work and can arbitrarily be applied and overridden. This is not a recommended mode of operation and can lead to unexpected deadlocks during database access. Tasks are not communicated on requests between applications that are running under the Application Profiling 5.x Compatibility Mode and applications that are not running under the compatibility mode.

For a v6 client to interact with applications run under the Application Profiling 5.x Compatibility Mode, set the appprofileCompatibility system property to true in the client process. We can do this by specifying the -CCDappprofileCompatibility=true option when invoking the launchClient command.

 

Procedure

  1. Configure application-managed tasks. Application profiling requires that a task name reference be declared for any task that is to be set programmatically. Task name references introduce a level of indirection so that the actual task set at run time can be adjusted by reassembly without requiring recoding or recompilation. Any attempt to set a task name that is undeclared as a task reference results in the raising of an exception. . If a unit of work has already begun when a task name is set, then that existing unit of work is not associated with the task name. Only units of work that are begun after the task name is set are associated with the task.

    Configure application-managed tasks as described in the following topics:

  2. Perform a Java Naming and Directory Interface (JNDI) lookup on the TaskNameManager interface:

    InitialContext ic = new InitialContext();
    TaskNameManager tnManager = ic.lookup
    ("java:comp/websphere/AppProfile/TaskNameManager");
    
    
    The TaskNameManager interface is not bound into the namespace if the application profiling service is disabled.

  3. Set the task name:

    try {
    tnManager.setTaskName("updateAccount");
    }
    catch (IllegalTaskNameException e) {
    // task name reference not configured. Handle error.
    }
    // . . .
    //
    
    
    Resetting the task name has no effect unless called by a J2EE 1.3 application executing on a server for which the 5.x Compatibility Mode attribute is selected on the Application Profile Service's console page. This is not a recommended mode of operation and can lead to unexpected deadlocks during database access. A call to resetTask( ) should only be used by J2EE 1.3 applications when the 5.x Compatibility mode is set to undo the effects of any setTaskName() method operations and reestablish whatever task name was current when the component began execution. If the setTaskName() method has not been called, the resetTaskName() method has no effect.

 

See also


TaskNameManager interface

 

Related Tasks


Configuring container managed tasks for Web components
Configuring container managed tasks for application clients
Configuring container managed tasks for Enterprise Java Beans