File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Architect Certification (SCEA/OCMJEA) and the fly likes Asynchronous Job withou JMS Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Architect Certification (SCEA/OCMJEA)
Bookmark "Asynchronous Job withou JMS" Watch "Asynchronous Job withou JMS" New topic

Asynchronous Job withou JMS

Dave Coopa

Joined: Aug 19, 2008
Posts: 2

I have a question regarding asynchronous process:
Let suppose a stateless EJB needs to perform a long process (say 5 min) but that the client does not want/need to wait until the process is finished.

In order to enable such process, is it required to use JMS: send a message to a MDB that will do the job?
It sounds strange to set up a messaging system only for processing long run tasks.

Thanks in advance for your opinions,

wang andrew
Ranch Hand

Joined: May 12, 2008
Posts: 31
you can spawn a new thread from the main thread, and let the new child thread take care of invoking EJB.
Dave Coopa

Joined: Aug 19, 2008
Posts: 2
Executing the work in a thread is what I would do for a client application. But in the server context it is prohibited to span thread because this process is not under control of the container (App Server). The application server should manage all the resources being indeed.

Any other idea ?
Gabriel Belingueres
Ranch Hand

Joined: Feb 09, 2007
Posts: 34
You could have a task that fires at regular time intervals to process all pending work. The work producer saves it into a shared repository (a database for example)
Jimmy Clark
Ranch Hand

Joined: Apr 16, 2008
Posts: 2187
It sounds strange to set up a messaging system only for processing long run tasks.

Sending a message from the Session EJB to a queue sounds like a good idea. This can be implemented rather easily and is very straight-forward.

A simple Message-Driven EJB will pick up the message and do the 5+ minute processing.
mc khan

Joined: Aug 14, 2008
Posts: 19
You can wrap your SLB as a JAS-WS webservice and let your client invoke it asynchronously or you can also wrap it as a one-way webservice. Internally the container would use helper threads to accomplish this.

According to the EJB3 spec you can also send a message to a local MBD without the need for MOM. I have not seen a real world example of this approach.

Good luck,
Chaminda Amarasinghe
Ranch Hand

Joined: May 17, 2006
Posts: 404

According to my experience MDB is a very good option for this type of situations. Other interesting thing with JMS-MDB is (ejb3) its supports for legacy systems as well,

Also Khan's suggestion seems a very good approach,

Good Luck
I agree. Here's the link:
subject: Asynchronous Job withou JMS
It's not a secret anymore!