| ||||||||||
Resin 3.1 Documentation Examples Changes Overview Installation Configuration Quercus SOA/IoC JSP Servlets and Filters Admin (JMX) EJB Amber Security Performance Hessian XML and XSLT Third-party Troubleshooting/FAQ Servlets Servlet Lib WebDAV run-at Filters Filter Lib FAQ |
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 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.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, automatically handles classloader issues. A thread implementation needs to ensure that the running thread has the same classloader as the application. Sample ServiceThe 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 and objects are just stubs. There's no reason to ever use them in a 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 and objects.package test; import javax.servlet.*; public class TestAlarm extends GenericServlet { public void service(ServletRequest request, ServletResponse response) throws IOException, ServletException { System.out.println("alarming"); } } The alarm is configured as any other servlet, with the addition of the tag. The following configuration runs the servlet every 15 minutes. If the hour is missing, e.g. the service is run at the specified minute.... <servlet name='alarm' servlet-class='test.TestAlarm'> <run-at>:00, :15, :30, :45</run-at> </servlet> ... You can also run an alarm every hour. Just specify the full hour:minute in the run-at. For example, runs the service once a day at 4:30 PM.... <servlet name='alarm' servlet-class='test.TestAlarm'> <run-at>16:30</run-at> </servlet> ...
|