Show TOC Start of Content Area

Procedure documentation Implementing the Work Management Contract  Locate the document in its SAP Library structure

Use

The work management contract that JCA 1.5 enables an inbound resource adapter to import work instances into multiple concurrent threads running on the application server. The work instances themselves are java.lang.Runnable objects but the resource adapter is not required to manage their execution.

The implementation of the work management contract on the AS Java side provides the following advantages:

      It enables thread pooling and reusing, which leads to a performance improvement.

      The server has a thorough mechanism for controlling threads. It is more effective and less error-prone to use this mechanism.

Caution

You must not implement additional thread execution logic in the resource adapter.

This procedure demonstrates the implementation of the work management contract on the resource adapter side.

Prerequisites

You have implemented the javax.resource.spi.work.Work interface. The implementation should override the run() method of the superinterface java.lang.Runnable, and the release() method of the superinterface javax.resource.spi.work.Work.

Procedure

Starting the Work

The adapter side of the work management implementation includes starting a work instance and passing it to the application server. To use this function, you have to implement the following in the start() method of the resource adapter JavaBean:

...

       1.      Get an instance of the Work Manager, implemented on the server side. To do this, invoke the getWorkManager()method of the BootstrapContext.

This graphic is explained in the accompanying text

public void start(BootstrapContext bootstrapCtx) throws ResourceAdapterInternalException {

         WorkManager workManager = bootstrapCtx.getWorkManager();

...

}

 

       2.      Construct a new work instance.

       3.      To import the work in the application server, invoke one of the following methods of the Work Manager:

       doWork – this call returns only after the work is completed or rejected

       startWork – this call returns when the work execution is started

       scheduleWork – this call returns immediately.

For all these methods you can also specify a timeout for executing the work, and send an execution context to the server.

Note

Using an execution context, you can also inflow transactions from the EIS to the application server. To do that, you must implement the javax.resource.spi.work.ExecutionContext class. The ExecutionContext object that you pass to the server contains the XID of a transaction initiated on the EIS.

More information: Transaction Inflow Support Implementation

Monitoring the Work Execution

To monitor the work execution:

...

       1.      Implement the javax.resource.spi.work.WorkListener interface.

       2.      Pass it as a parameter to one of the start methods (doWork, startWork, or scheduleWork) of the application server Work Manager. This enables the resource adapter to receive events when the work is accepted or rejected, as well as when it is started or completed.

Caution

If the thread blocks or an exception is thrown in a work listener’s method, the overall work processing fails.

Releasing the Work Instance

Call the release() method of the work instance in the stop() method of the resource adapter JavaBean. This enables the orderly shutdown of the resource adapter.

End of Content Area