Menu Close
Settings Close

Language and Page Formatting Options

3.13. Asynchronous Handlers

To implement an asynchronous service handler using simple Java, execute the actual service in a new thread:
public class MyServiceTaskHandler implements WorkItemHandler {
        
  public void executeWorkItem(WorkItem workItem, WorkItemManager manager) {
    new Thread(new Runnable() {
      public void run() {
        // Do the heavy lifting here ...
      }
    }).start();
  }

  public void abortWorkItem(WorkItem workItem, WorkItemManager manager) {
  }
      
}
In general, a handler usually will not implement the business logic to perform the work item but will contact an existing service to do the work. For example, the human task handler simply invokes the human task service to add a task there. To implement an asynchronous handler, you usually have to do an asynchronous invocation of this service. This usually depends on the technology you use to do the communication, but this might be as simple as asynchronously invoking a web service, sending a JMS message to the external service, etc.