Before you begin
Your administrator must have configured at least one work manager using the administrative console.Why and when to perform this task
To run code in parallel, or in a different J2EE context, wrap the code in a work object.
Steps for this task
A work object implements the com.ibm.websphere.asynchbeans.Work interface. For example:
class SampleWork implements Work
InitialContext ic = new InitialContext(); WorkManager wm = (WorkManager)ic.lookup("java:comp/env/wm/myWorkManager");
Work w = new MyWork(...); WorkItem wi = wm.startWork(w);
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. }
public synchronized void release() { released = true; }The Work.run() method can periodically examine this variable to check whether the loop exits or not.