Scheduled Task

From Resin 3.0

Jump to: navigation, search

When you want to run a task at a specific interval like a report every night at midnight, you can use Resin's <resin:ScheduledTask> bean. The scheduled task will take your custom Runnable bean, or a URL and execute it at the specific time.

The following configuration in the WEB-INF/resin-web.xml will instantiate your custom bean at midnight every night.

<web-app xmlns="http://caucho.com/ns/resin"
        xmlns:resin="urn:java:com.caucho.resin"
        xmlns:mypkg="urn:java:com.mycom.mypkg">

  <resin:ScheduledTask>
    <cron>* * 0</cron>
    <task>
       <mypkg:MyBean/>
    </task>
  </resin:ScheduledTask>

</web-app>
  • The xmlns:mypkg defines the XML prefix for your bean's Java package
  • The <resin:ScheduledTask> creates Resin's scheduled task bean
  • The <cron> defines the schedule times, using Unix-style cron (sec, min, hour, day)
  • The <task> is where your custom bean fits.

Your bean will be any Java class implementing Runnable:

package com.mycom.mypkg;

public class MyBean implements Runnable {

  public void run()
  {
    System.out.println("Running!");
  }

}
Personal tools