users@glassfish.java.net

Re: How could I implement and deploy a background process in Glassfish?

From: <glassfish_at_javadesktop.org>
Date: Tue, 15 Jan 2008 13:26:24 PST

> To me it seems really heavyweight. If you absolutely
> need a portable (read
> nothing beyond JEE), clusterable and multi-threaded
> solution this is it.

It's only heavyweight if you don't already have the JEE infrastructure. If you do already have it, it's pretty straightforward requiring only a Session Bean, and Message Driven Bean (which are just POJO's today), small bit of code to prime the timer, and a queue on the server. All told, there's maybe 30-40 lines of code required to pull this off, plus your actual logic.

Its APPEARS heavyweight because of the need of the JEE infrastructure, but once you've taken that step, this is almost free. Hardest part for most is getting JMS set up, and Netbeans has a wizard that will do that for you.

> On the other hand you may decide you don't REALLY have
> that needs. How would I do it then?

If I didn't do it this way, I'd create a thread in one of the WAR instances and be done with it. Tie some lifecycle bits to the ContextListener and go my merry way. The Java 5 concurrent services make this stuff pretty easy to do. Or I'd take it out of the server completely and run it as a standalone service feeding a remote JMS queue. Tie it in to Solaris's SMF service and never think of it again.

All of this can be readily done simply with the JDK.
[Message sent by forum member 'whartung' (whartung)]

http://forums.java.net/jive/thread.jspa?messageID=254075