Your administrator must have configured at least one work manager using the administrative console.
To run code in parallel, or in a different J2EE context, wrap the code in a work object.
class SampleWork implements Work
InitialContext ic = new InitialContext(); WorkManager wm = (WorkManager)ic.lookup("java:comp/env/wm/myWorkManager");The resource reference for the work manager (in this case, wm/myWorkManager) must be declared as a resource reference in the application deployment descriptor.
Work w = new MyWork(...); WorkItem wi = wm.startWork(w);The startWork() method can take a startTimeout parameter. This specifies a hard time limit for the Work object to be started. The startWork() method returns a work item object. This object is a handle that provides a link from the component to the now running work object.
WorkItem wiA = wm.start(workA); WorkItem wiB = wm.start(workB); ArrayList l = new ArrayList(); l.add(wiA); l.add(wiB); if(wm.join(l, wm.JOIN_AND, 5000)) // block for up to 5 seconds { // both wiA and wiB finished } else { // timeout // we can check wiA.getStatus or wiB.getStatus to see which, if any, finished. }This method takes an array list of work items which your component wants to wait on and a flag that indicates whether the component will wait for one or all of the work objects to complete. You also can specify a timeout value.
public synchronized void release() { released = true; }The Work.run() method can periodically examine this variable to check whether the loop exits or not.
Related concepts
References