Search

3.13. Asynchronous Handlers

download PDF
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.
Red Hat logoGithubRedditYoutubeTwitter

Learn

Try, buy, & sell

Communities

About Red Hat Documentation

We help Red Hat users innovate and achieve their goals with our products and services with content they can trust.

Making open source more inclusive

Red Hat is committed to replacing problematic language in our code, documentation, and web properties. For more details, see the Red Hat Blog.

About Red Hat

We deliver hardened solutions that make it easier for enterprises to work across platforms and environments, from the core datacenter to the network edge.

© 2024 Red Hat, Inc.