Monday, March 09, 2009

Schedulers in web applications

What if your web application requires some periodical process? It is good when your hosting provides some kind of cron tab scheduler, lets you invoke your own application, but it is not so widely used option. One trick we've used for example in Twitter 411 mashup (periodical polling with Twitter API) simply "borrows" requests from site visitors. You can add to your site a hidden (invisible) iframe where src attribute points to the "scheduler". And your "scheduler" will perform the requests to your periodical tasks (implemented as JSP pages or servlets). This trick described here. But it is applied level timer support.

Another option (system level) is Lifecycle modules. Lifecycle listener modules provide a means of running short or long duration Java-based tasks within the application server environment, such as instantiation of singletons or RMI servers. These modules are automatically initiated at server startup and are notified at various phases of the server life cycle.The lifecycle module classes are called synchronously from the main server thread and Lifecycle modules can create threads if appropriate.

And the third option is writing custom MBeans. See for example Timer MBean

Please add your site at http://www.sweebs.com. Sweebs.com is a place where other people can find you among the best sites on the internet!Its just started and we are collecting the best found on the net! We will be delighted to have you in the sweebs listings.