Sometimes you need to execute methods in async way.
There are several ways which you can do it
- 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.
- 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:
executorService.submit(callable);
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:
Post a Comment