在Weblogic中使用定时器(commonj Timer for weblogic server)
2006-04-28 17:35
701 查看
1.简介
由于J2EE规范的限制,在Servlet和EJB中执行用户自定义的多线程并发与定时器服务一直以来是困扰J2EE开发人员的一个大问题。现在CommonJ项目中的Work Manager和Timer规范将是解决这些问题的一个优秀方法。
CommonJ 定时器(Timer)规范提供了一个在Servlet和EJB中设置定时器的简单方法,同时允许在Servlet和EJB中响应定时器的提醒。该规范提供了一个在不能或者不方便使用java.util.Timer环境中使用定时器功能的替代方法。
现在在WebLogic Server 9.0中已经提供了对Work Manager和Timer规范的支持,在WebLogic Server 7和8中需要使用该项功能请参考这里,xcommonj-work。
关于Work Manager和Timer规范的更多信息请访问这里:Timer and Work Manager for Application Servers。
在J2EE中使用 Work Manager 规范执行并行任务,请访问这里:http://dev2dev.bea.com.cn/techdoc/200508631.html
Commonj定时器的参考请见这里:http://dev2dev.bea.com.cn/techdoc/20051221711.html
2.定时器的使用办法:
(1)在web.xml或者ejb-jar.xml中增加定时器的描述:
<resource-ref>
<res-ref-name>timer/MyTimer</res-ref-name>
<res-type>commonj.timers.TimerManager</res-type>
<res-auth>Container</res-auth>
<res-sharing-scope>Unshareable</res-sharing-scope>
</resource-ref>
(2)定义定时器到时间的回调类:
import commonj.timers.*;
public class TestListener
implements TimerListener
{
public TestListener()
{
}
public void timerExpired(Timer timer)
{
System.out.println("TimerExpired.");
}
}
(3)在其它任何地方启动定时器,并设置定时器的任务即可实现定时功能了。
InitialContext ctx = new InitialContext();
TimerManager mgr = (TimerManager)ctx.lookup("java:comp/env/timer/MyTimer");
TimerListener listener = new TestListener();
mgr.schedule(listener,4000);//定时器执行一次
mgr.scheduleAtFixedRate(listener,5000,2000);//定时器周期执行
//按照日历来执行定时器
Calendar cal = Calendar.getInstance();
cal.set(Calendar.HOUR, 12);
mgr.schedule(listener, cal.getTime());
由于J2EE规范的限制,在Servlet和EJB中执行用户自定义的多线程并发与定时器服务一直以来是困扰J2EE开发人员的一个大问题。现在CommonJ项目中的Work Manager和Timer规范将是解决这些问题的一个优秀方法。
CommonJ 定时器(Timer)规范提供了一个在Servlet和EJB中设置定时器的简单方法,同时允许在Servlet和EJB中响应定时器的提醒。该规范提供了一个在不能或者不方便使用java.util.Timer环境中使用定时器功能的替代方法。
现在在WebLogic Server 9.0中已经提供了对Work Manager和Timer规范的支持,在WebLogic Server 7和8中需要使用该项功能请参考这里,xcommonj-work。
关于Work Manager和Timer规范的更多信息请访问这里:Timer and Work Manager for Application Servers。
在J2EE中使用 Work Manager 规范执行并行任务,请访问这里:http://dev2dev.bea.com.cn/techdoc/200508631.html
Commonj定时器的参考请见这里:http://dev2dev.bea.com.cn/techdoc/20051221711.html
2.定时器的使用办法:
(1)在web.xml或者ejb-jar.xml中增加定时器的描述:
<resource-ref>
<res-ref-name>timer/MyTimer</res-ref-name>
<res-type>commonj.timers.TimerManager</res-type>
<res-auth>Container</res-auth>
<res-sharing-scope>Unshareable</res-sharing-scope>
</resource-ref>
(2)定义定时器到时间的回调类:
import commonj.timers.*;
public class TestListener
implements TimerListener
{
public TestListener()
{
}
public void timerExpired(Timer timer)
{
System.out.println("TimerExpired.");
}
}
(3)在其它任何地方启动定时器,并设置定时器的任务即可实现定时功能了。
InitialContext ctx = new InitialContext();
TimerManager mgr = (TimerManager)ctx.lookup("java:comp/env/timer/MyTimer");
TimerListener listener = new TestListener();
mgr.schedule(listener,4000);//定时器执行一次
mgr.scheduleAtFixedRate(listener,5000,2000);//定时器周期执行
//按照日历来执行定时器
Calendar cal = Calendar.getInstance();
cal.set(Calendar.HOUR, 12);
mgr.schedule(listener, cal.getTime());
相关文章推荐
- web容器中使用Timer定时器
- java 定时器timer的使用
- IAR FOR AVR 定时器中断的使用
- C#中定时器timer的使用
- Java Timer 定时器的使用
- Troubleshot for SSL issue for Weblogic server
- weblogic server with Jrockit. Good for better performance
- IAR For AVR 定时器溢出中断 (使用小结)
- Java 中Timer和TimerTask 定时器和定时任务使用的例子
- asp.net 线程定时器(Timer )的使用
- ArcSDE10 for SQL Server使用GEOMETRY或GEOGRAPHY存储性能问题
- System.Thread.Timer定时器的使用
- [小道消息]Microsoft .NET Framework 4 For Server Core 可以使用啦
- Java Timer 定时器的使用
- timer和ScheduledExecutorService延时器与定时器的使用
- C# 使用定时任务 之 谈谈定时器(Timer)的使用
- MAC中使用svn时报证书验证错误Error validating server certificate for…的解决办法
- matlab 使用定时器timer
- 使用JMX访问WebLogic Server MBean(监控应用服务器系列文章)
- 在weblogic 10 的集群环境中使用EJB 3 timer