<document>
<deftable>
Configures the CronResource
The work task executes the long task.
The starting page for the tutorial
</deftable>

Resin provides a convenience resource, `com.caucho.resources.CronResource` to execute `javax.resource.Work` tasks at configurable intervals. Essentially, it implements the Timer/Work resource combination described in the timer tutorial.

The `Work` task follows the standard JCA API; no Resin-specific code is required. The tutorial example stores a string in JNDI to be retrieved by the example JSP.

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>

For 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() { } }

The 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") %>
</document>