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

📄 timerresource.java

📁 RESIN 3.2 最新源码
💻 JAVA
字号:
package example;import java.util.Timer;import java.util.TimerTask;import java.util.logging.Logger;import javax.resource.spi.ResourceAdapter;import javax.resource.spi.ResourceAdapterInternalException;import javax.resource.spi.BootstrapContext;import javax.resource.spi.work.Work;import javax.resource.spi.work.WorkManager;import javax.resource.spi.work.WorkException;import com.caucho.jca.AbstractResourceAdapter;import com.caucho.config.types.Period;/** * Implements a resource which uses uses Work management for * separate threading. */public class TimerResource extends AbstractResourceAdapter {  private static final Logger log =    Logger.getLogger(TimerResource.class.getName());  // The initial delay of the task.  private long _initialDelay = 0;    // The period of the task  private long _period = 10000L;    // The count of times the server has looped  private int _count;  private Timer _timer;  /**   * Sets the initial delay using the Resin-specific period notation:   * 10s, 10m, etc.   */  public void setInitialDelay(Period initialDelay)  {    _initialDelay = initialDelay.getPeriod();  }  /**   * Sets the period using the Resin-specific period notation:   * 10s, 10m, etc.   */  public void setPeriod(Period period)  {    _period = period.getPeriod();  }    /**   * Adds to the count.   */  public void addCount()  {    _count++;  }    /**   * The start method is called when the resource adapter starts, i.e.   * when the web-app or host initializes.   */  public void start(BootstrapContext ctx)    throws ResourceAdapterInternalException  {    log.info("WorkResource[] starting");    WorkManager workManager = ctx.getWorkManager();        Work work = new WorkTask(this);    TimerTask timerTask = new WorkScheduleTimerTask(workManager, work);    _timer = ctx.createTimer();    _timer.schedule(timerTask, _initialDelay, _period);  }    /**   * Called when the resource adapter is stopped, i.e. when the   * web-app or host closes down.   */  public void stop()    throws ResourceAdapterInternalException  {    log.info("Resource[" + _count + "] stopping");    _timer.cancel();  }  /**   * Returns a printable version of the resource.   */  public String toString()  {    return "WorkResource[" + _count + "]";  }}

⌨️ 快捷键说明

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