⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 index.xtp

📁 RESIN 3.2 最新源码
💻 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">&lt;resource type="com.caucho.resources.CronResource"&gt;  &lt;init&gt;    &lt;cron&gt;*/5&lt;/cron&gt;    &lt;work resin:type="example.WorkTask"&gt;      &lt;value&gt;Example&lt;/value&gt;      &lt;jndi&gt;java:comp/env/example&lt;/jndi&gt;    &lt;/work&gt;  &lt;/init&gt;&lt;/resource&gt;</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">&lt;%@ page import="javax.naming.*" %&gt;&lt;%= new InitialContext().lookup("java:comp/env/example") %&gt;</example></s1></body></document>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -