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,
Joined: May 12, 2008
you can spawn a new thread from the main thread, and let the new child thread take care of invoking EJB.
Joined: Aug 19, 2008
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 ?
Joined: Feb 09, 2007
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)
Joined: Apr 16, 2008
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.
Joined: Aug 14, 2008
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, -Maqbool.
Joined: May 17, 2006
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,