Reference Guide

JSP page
Database Forms
XTP Copy
Hello Tag
Vary Filter
Mailing Forms
XSL Filter
 run-at: Periodic Services

XSL Filter

Some web applications need a task to be run at regular intervals, e.g. once an hour or once a day. For example, a search application might want to spider the web site every day to automatically pick up any new pages. Syndication applications might poll their news sites every hour to check for updates.

Resin's run-at servlets make periodic tasks simple. At the specified interval, Resin will execute a configured servlet. Because the periodic task is implemented as a servlet, the API is familiar and debugging is simple.

run-at has several advantages over spawning a new thread. First, when you spawn a thread, you need to make sure you close it properly when the servlet is unloaded. Servlets can be unloaded at any time. Also, run-at automatically handles classloader issues. A thread implementation needs to ensure that the running thread has the same classloader as the application.

Sample Service

The following example doesn't do much. When the service routine is called, is just prints a message to the standard output.

Because there is no request, the request and response objects are just stubs. There's no reason to ever use them in a run-at service. (Yes, that makes the arguments a little silly, but it's better than creating a new API.)

The service does have access to the ServletConfig and ServletContext objects.
package test;

import javax.servlet.*;

public class TestAlarm extends GenericServlet {
  public void service(ServletRequest request,
                      ServletResponse response)
    throws IOException, ServletException

The alarm is configured as any other servlet, with the addition of the run-at tag. The following configuration runs the servlet every 15 minutes. If the hour is missing, e.g. :15 the service is run at the specified minute.

15 minute configuration
<servlet name='alarm' servlet-class='test.TestAlarm'>
  <run-at>:00, :15, :30, :45</run-at>

You can also run an alarm every hour. Just specify the full hour:minute in the run-at. For example, 16:30 runs the service once a day at 4:30 PM.

Daily at 4:30 PM Configuration
<servlet name='alarm' servlet-class='test.TestAlarm'>

XSL Filter
Copyright © 1998-2002 Caucho Technology, Inc. All rights reserved.
Resin® is a registered trademark, and HardCoretm and Quercustm are trademarks of Caucho Technology, Inc.