📄 index.xtp
字号:
<document><header><product>resin</product><type>tutorial</type><title>CronResource</title><description><p>CronResource is a convenient resource which schedules application Worktasks at configurable intervals.</p></description> <tutorial-startpage>index.jsp</tutorial-startpage></header><body><summary/><s1 title="Files in this tutorial"><deftable><tr><td><viewfile-link file="WEB-INF/web.xml"/> </td><td>Configures the CronResource</td></tr><tr><td><viewfile-link file="WEB-INF/classes/example/WorkTask.java"/> </td><td>The work task executes the long task.</td></tr><tr><td><viewfile-link file="index.jsp"/> </td><td>The starting page for the tutorial</td></tr></deftable></s1><s1 title="CronResource"><p>Resin provides a convenience resource,<code>com.caucho.resources.CronResource</code> toexecute <code>javax.resource.Work</code> tasks at configurable intervals.Essentially, it implements the Timer/Work resource combination describedin the <a href="../jca-timer">timer tutorial</a>.</p><p>The <code>Work</code> task follows the standard JCA API; no Resin-specificcode is required. The tutorial example stores a string in JNDI to beretrieved by the example JSP.</p><p>The cron times follow the Unix crontab format. The tutorial schedulesthe work task every 5 minutes, using the "*/5" pattern. More details forthe cron specificiations is available in the<a href="doc|soa-cron.xtp#CronResource">CronResourcedocumentation.</a></p><example title="sample web.xml"><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></example></s1><s1 title="The work task"><p>For this example, the work task is trivial. It just sets astring in JNDI.</p><example title="WorkTask.java">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() { }}</example></s1><s1 title="JSP"><p>The demo JSP is also trivial. It looks up the resource throughJNDI and prints it to the page.</p><example title="index.jsp"><%@ page import="javax.naming.*" %><%= new InitialContext().lookup("java:comp/env/example") %></example></s1></body></document>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -