Weblog

All | Personal | Sun
« Where is the NetBean... | Main | Faster deployment to... »
20060220 Monday February 20, 2006

How to implement cron in Enterprise application One my colleague asked me for implementing cron functionality in J2EE applicationthat is deployed in Sun application server. He needs to execute scheduled commandsin his EJB module. I suggested folowing solution that consists of Timer bean and lifecycle module that starts the timer when the server is started.
I know that better solution is used lifecycle module that is connected to EJB module only. For instance, where the module is deployed the lifecycle listener can invoke the bean. However, Sun Application server doesn't support this type lifecycle listener. The WebLogic server supports lifecycle listeneres on module application level, see here. Other solution is use servlet life cycle listener in web tier but this suggestion adds additional dependency for J2EE application. Since I didn't find better solution I used lifecycle module and Timer bean. Steps are below:

Posted by pblaha ( Feb 20 2006, 05:41:41 PM CET ) Permalink Comments [4]

Comments:

There needs to be a mechanism in the EJB spec to support the EJB container lifecycle. The part I hate about this solution is the vendor specific lifecycle class. There are ServletContextListeners in the web tier, why can't we have something similar in the EJB tier that is standard?

Posted by 207.203.254.110 on February 21, 2006 at 05:53 PM CET #

Self management framework in GlassFish has predefined "timer" event. This timer event has similar capabilities as javax.management.timer package. Timer event can be defined as one time event at specified time or a repetitive event with periodicity and number of occurrences specified. </br> So the basic infrastructure is available and no piece of code is required to be written as far as saying call this business logic at this point of time and at a interval of for this many number of times. </br> Now, the business logic can be written as an MBean which implements javax.management.NotificationListener. Once this is done, a management rule can be created with event being "timer" and action being the MBean with the business logic. </br> Some useful info:</br> Self Management Framework in GlassFish</br> GlassFish : Self Management Rules</br> GlassFish Project : Self Management home </br>

Posted by sankara on February 22, 2006 at 07:53 AM CET #

Thanks sankara for your comment, I will try to rewrite the sample. I didn't know about this solution. I agree that suggested solutions has a server specific dependency. However, I didn't find better before :-(

Posted by Petr on February 22, 2006 at 01:23 PM CET #

The solution described by sankara is avalible in Glassfish only but it's not avalaible in App server 8.1

Posted by Petr on February 22, 2006 at 01:47 PM CET #

Post a Comment:

Comments are closed for this entry.

Calendar

RSS Feeds

Search

Links

Navigation

Referers

Older blog entries