Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Asynchronous Job withou JMS

 
Dave Coopa
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

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,

Dave
 
wang andrew
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
you can spawn a new thread from the main thread, and let the new child thread take care of invoking EJB.
 
Dave Coopa
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2187
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Chaminda Amarasinghe
Ranch Hand
Posts: 413
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic