Network Deployment (Distributed operating systems), v8.0 > Develop and deploying applications > Develop Application profiling


Use the TaskNameManager interface

Use the TaskNameManager interface, you can programmatically set the current task name. It 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 running 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.

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

    To complete these tasks see the assembly tool information center:

    • Configure application managed tasks for web components.

    • Configure application managed tasks for application clients.

    • Configure application managed tasks for Enterprise JavaBeans.

  2. Perform a 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.
    }
    // . . .
    //
    
    
    The name passed to the setTaskName() method ("updateAccount" in this example) is actually a task name reference that you configured in step one.
  4. Begin a UserTransaction

    If you are using a J2EE 1.3 application with the 5.x Compatibility mode set, the task name set in step 3 is now the active task name and you can disregard this step. If you are using a J2EE application and the compatibility mode is not set, or if you are using a J2EE 1.4 application, begin a transaction for the task name to become active. A task name can only be associated with a transaction. Furthermore, it is associated with a transaction when that transaction is begun, and that task name is associated with the transaction for the life of the transaction. Therefore, the task name set above is not active at this point. We must begin a UserTransaction as the following code snippet illustrates:

    try{
        InitialContext initCtx = new InitialContext();
        userTran = (UserTransaction) initCtx.lookup("java:comp/UserTransaction");
        userTran.begin();
    }
    catch(Exception e){
    }  
    // . . .
    //
    
    Notice the resetTaskName() method on the TaskNameManager interface. Resetting the task name has no effect unless called by a J2EE 1.3 application running 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.


Related


TaskNameManager interface
Use the transaction service


Related


//publib.boulder.ibm.com/infocenter/wasinfo/v8r0/index.jsp?topic=/ ://publib.boulder.ibm.com/infocenter/radhelp/v7r5mbeta/topic/com.ibm.jee5.doc/topics/cejb3.html

+

Search Tips   |   Advanced Search