| ||||||||||
CronResource is a convenient resource which schedules application Work tasks at configurable intervals. Files in this tutorial
CronResourceResin provides a convenience resource,
The The cron times follow the Unix crontab format. The tutorial schedules the work task every 5 minutes, using the "*/5" pattern. More details for the cron specificiations is available in the CronResource documentation. <resource type="com.caucho.resources.CronResource"> <init> <cron>*/5</cron> <work resin:type="example.WorkTask"> <value>Example</value> <jndi>java:comp/env/example</jndi> </work> </init> </resource> The work taskFor this example, the work task is trivial. It just sets a string in JNDI. public class WorkTask implements Work { private String _value = "default"; private String _jndi = "java:comp/env/test"; public void setValue(String value) { _value = value; } public void setJNDI(String value) { _jndi = jndi; } public void run() { try { new InitialContext().rebind(_jndi, _value + ": " + new Date()); } catch (Throwable e) { e.printStackTrace(); } } public void release() { } } JSPThe demo JSP is also trivial. It looks up the resource through JNDI and prints it to the page. <%@ page import="javax.naming.*" %> <%= new InitialContext().lookup("java:comp/env/example") %>
|