EJB3.0 Timer
2014-06-26 15:35
387 查看
1. 创建一个Session Bean
2. 注入SessionContext Resource
3. 构造一个Timer
4. 利用@Timeout注解定义定时任务的具体执行
@Timeout注解的定时任务方法签名的格式 public void methodName(Timer timer){}
2. 注入SessionContext Resource
3. 构造一个Timer
4. 利用@Timeout注解定义定时任务的具体执行
package com.icode.jejb.time; /** * Created with IntelliJ IDEA. * User: alexz * Date: 14-6-25 * Time: 下午4:44 * To change this template use File | Settings | File Templates. */ public interface TimerTask { void start(); }
package com.icode.jejb.time; import javax.annotation.Resource; import javax.ejb.*; import java.util.Date; /** * Created with IntelliJ IDEA. * User: alexz * Date: 14-6-25 * Time: 下午4:44 * To change this template use File | Settings | File Templates. */ @Stateless @Remote(value = TimerTask.class) public class SimpleTimerTask implements TimerTask { private int count = 0; @Resource private SessionContext sessionContext; public SimpleTimerTask() { System.out.println("Instance the SimpleTimerTask Bean!!!!!!!!!!!!!"); } @Timeout public void execute(Timer timer) { String params = (String) timer.getInfo(); System.out.println(count + ": " + params); count++; } @Override public void start() { TimerService timerService = sessionContext.getTimerService(); timerService.createTimer(new Date(new Date().getTime() + 2000), 3000, "This is my first timer task!!!"); } }
@Timeout注解的定时任务方法签名的格式 public void methodName(Timer timer){}
相关文章推荐
- Android中的DatePick和TimerPick全
- 任务调度(四)——ScheduledExecutorService替代Timer,实现多线程任务调度
- Timer和TimerTask
- Data transfer from GPIO port to RAM buffer using DMA upon receiving a trigger signal on the timer capture input channel.
- PB 利用timer()函数实现定时将数据窗口以excel文档保存至指定地方
- Python游戏服务器开发日记(五)skynet_messagequeue和skynet_timer
- 【Java多线程】-Timer,TimerTask,ScheduledExecutorService
- 【Android】轮询的若干问题 Timer, TimerTask;Timer 的缺陷,ScheduledThreadPoolExecutor
- android--计时器(Timer)
- wx.Timer来设置定时事件(绑定定时器)
- Java中Timer的用法详解
- 《TCP/IP详解 卷一》读书笔记-----TCP persist &Keeplive timer
- Java学习:Timer与ScheduledExecutorService的区别
- Timer和TimerTask
- 定时任务实现Timer, TimeTask, ScheduledExecutorService及Spring定时器
- 使用Timer类的动画
- Timer的缺陷 用ScheduledExecutorService替代
- Spring框架之TimerTask使用
- Arduino - 看门狗定时器(WDT:Watch Dog Timer)
- timer