Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

Work can be scheduled for asynchronous execution by submitting it to the runtime ExecutorService thread pool. To obtain a reference to the service, use the Fabric3 @Resource annotation:

Code Block
java
java

public class SomeComponent ... {

   @Resource
   protected ExecutorService executorService;

   @Reference
   protected TargetService targetService;

   public void doSomething() {
      executorService.submit(new Runnable() {
         public void run() {
          // invoke the service
          targetService.invoke();
         }
      }
   }

}

The executing thread will inherit the current component work context during the time the submitted Runnable is invoked.

Note that in most cases SCA one-way operations (@OneWay) should be used instead of manually submitting asynchronous work as less code is required.