近况

十二月 19th, 2011 12:23上午 Post in 蓝色点滴

差不多四个月没什么实质更新啦。。

毕业了,时间没以前那么多了,闲下来也不想去折腾什么,所以也不想去随便洒些水。。。

工作压力一天天上去,加班也越来越多。。终于进入12月份开始了连续的加班通宵无周末休息。。

……………………………………………………….

最近抱怨的也有些多,但毕竟自己已经走在社会的路上,有些东西是必须经历的。。

最近打算回家看看吧。。前段时间入手了一部wp7,htc莫扎特,研究研究这个了。。

end。。

中秋快乐..

九月 12th, 2011 12:27上午 Post in 蓝色点滴

祝大家中秋快乐!!^_~~

EJB3.1 Timer Service

八月 20th, 2011 4:57下午 Post in Java EE

最近做了一个定时发送邮件的功能,主要是采用了EJB3.1提供的定时功能。

接触EJB的时间不长,博客又快要长草,简单记录下来正好除除草。呵呵。。

参考了oracle的 The Java EE 6 Tutorial和 JAVA EE API

http://download.oracle.com/javaee/6/tutorial/doc/bnboy.html  Using the Timer Service

http://download.oracle.com/javaee/6/api/     Class ScheduleExpression

Enterprise bean timers are either programmatic timers or automatic timers :

记录两个小demo类,注意点写在注释里了,服务器使用JBOSS AS6.0

programmatic timers:编程

@Singleton
@Startup
public class TimerBean {
	static boolean ENABLE_PERSISTENY = false;
	@Resource
	private TimerService timerService;
	static Logger logger = Logger.getLogger(TimerBean.class);
	@PostConstruct
	public void init() {
		ScheduleExpression scheduleExpression = new ScheduleExpression();
		TimerConfig timerConfig = new TimerConfig();
		//设置persistent
		timerConfig.setPersistent(ENABLE_PERSISTENY);
		timerConfig.setInfo(TimerBean.class.getName());
		//每10秒执行一次
		scheduleExpression.hour("*").minute("*").second("*/10");
		Timer timer=timerService.createCalendarTimer(scheduleExpression,timerConfig);
	}
	@Timeout
	public void execute(Timer timer) {
		logger.info(timer.getInfo()+":"+timer.getNextTimeout().getTime());
	}
}

 

automatic timers:注解

@Singleton
@Startup
public class ScheduleBean {
	static Logger logger=Logger.getLogger(ScheduleBean.class);
	//一分钟一次
	//注意second="0",不是"*"
	//persistent设置
	@Schedule(persistent=false, hour="*", minute="*/1", second="0")
	public void test(){
		logger.info("ScheduleBean....."+new Date().getTime());
	}
}

设置persistent:

timerConfig.setPersistent(false);

@Schedule(persistent=false..

这样做的原因是:

Timers are persistent by default. If the server is shut down or crashes, persistent timers are saved and will become active again when the server is restarted. If a persistent timer expires while the server is down, the container will call the @Timeout method when the server is restarted.

Timers默认会被持久化。

如果遇到timeout method 方法找不到异常,或者已经修改的定时方法仍然起效,原因就是这个参数的了

清空JBOSS主目录\server\[default]\data文件夹即可。

(一开始没注意这个。。我把先写的一个方法删掉,提交到了SVN,结果导致组里N多人无法启动。。)

eclipse工程文件 下载

运行结果:ScheduleBean的方法一分钟一次,TimerBean的10秒一次

15:18:00,046 INFO  [com.rainripple.ejb.timer.ScheduleBean] ScheduleBean.....1313824680046
15:18:10,002 INFO  [com.rainripple.ejb.timer.TimerBean] com.rainripple.ejb.timer.TimerBean:1313824700000
15:18:20,003 INFO  [com.rainripple.ejb.timer.TimerBean] com.rainripple.ejb.timer.TimerBean:1313824710000
15:18:30,003 INFO  [com.rainripple.ejb.timer.TimerBean] com.rainripple.ejb.timer.TimerBean:1313824720000
15:18:40,002 INFO  [com.rainripple.ejb.timer.TimerBean] com.rainripple.ejb.timer.TimerBean:1313824730000
15:18:50,003 INFO  [com.rainripple.ejb.timer.TimerBean] com.rainripple.ejb.timer.TimerBean:1313824740000
15:19:00,003 INFO  [com.rainripple.ejb.timer.TimerBean] com.rainripple.ejb.timer.TimerBean:1313824750000
15:19:00,005 INFO  [com.rainripple.ejb.timer.ScheduleBean] ScheduleBean.....1313824740005

出差ing

七月 21st, 2011 10:03下午 Post in 蓝色点滴

最近一直都是在北京出差,来的时候做的高铁,幸运的是我们那列安全到达北京,
然后几小时后的那辆就杯具了。。上周末抽了一个下午到故宫转了一圈,可惜没带相机。。
人山人海的匆匆逛了一些,然后直接做地铁回去工作了。。这一周多的时间把周围能吃饭的地方转了一遍,
可惜我不喜欢吃荤,本来我家就是偏北方的,所以也没什么特别的。。
工作一直很紧的,除了吃饭的时候能跑跑,其它时间都是做在电脑旁。。。。。。。。

Sth

六月 21st, 2011 6:15下午 Post in 蓝色点滴

博客几天一直不能访问,原来是空间的ip地址变了。。。

数据我恢复到了6月8日(这个纯属失误),丢了几个评论,暂时这样了