Sunday, March 9, 2008

Execute Async Method

Sometimes you need to execute methods in async way.

There are several ways which you can do it

  1. Send JMS message in J2EE Application with a Callback object, Write MDB which would listen to the Queue which you send the message to, When the MDB would finish it would call the method 'done' on the Callback if the execution succeed, and it the execution failed it would call the method 'failed' on the Callback.
  2. If you write with Java 1.5 simple small Java Program and you don't need to distribute your async command in cluster environment you can use the 'Executors' class to create pool of executions in this way:

ScheduledExecutorService executorService = Executors.newScheduledThreadPool(10);

and then just write:


This would execute the callbale call method in async way, You can pass callback to the

callable object which would later be called to send the response back.

No comments:


RSS Feeds Submission Directory