The java.util.concurrent.ExecutorService interface represents an asynchronous execution mechanism which is capable of executing tasks in the background of a BPEL transaction.
An ExecutorService is thus very similar to a thread pool. In fact, the implementation of ExecutorService present in the java.util.concurrentpackage is a thread pool implementation.
The below code could be incorporated into JCD (Java Collaboration Definition) to achieve concurrency in JCAPS - BPEL:
/**
* JCD Code: Asynchronous call to invoke any method * * * * @author Manesh Abhimanyu * @param String Input 1 * @param String Input 2 */ public void asyncServiceMethod( final String input1, final String input2) { ExecutorService executor = Executors.newSingleThreadExecutor(); try { Runnable task = new Runnable(){ public void run() { try { invokeJCAPSMentor( input1, input2 ); } catch ( Exception ex ) { // handle error which cannot be thrown back } } }; executor.execute( task ); } catch ( Exception e ) { // handle error which cannot be thrown back } finally { // gargabe collect executor.shutdown(); } }
More reading:
Labels: advantages jcaps 6, Asynchronous, Asynchronous in jcaps component, JavaCaps, JCD, manesh, Thread JCAPS, Thread JCD |