简体   繁体   English

Java EE计划任务

[英]Java EE Scheduled task

I need to schedule a task to be run periodicily (eg every 6 hours, or maybe everyday at 12 PM) on Weblogic 10.3 server. 我需要在Weblogic 10.3服务器上安排定期运行任务(例如每6个小时,或者每天12点)。 The task basically retrieves some data from the database and does some business logic with it. 该任务基本上从数据库中检索一些数据,并用它做一些业务逻辑。

What is the best way to achieve this? 实现这一目标的最佳方法是什么? I have searched the internet, and found some solutions like: 我搜索了互联网,发现了一些解决方案:

  • Using the Timer Service. 使用定时服务。
  • Work Managers. 工作经理。
  • EJB Timers. EJB计时器。

And BTW, I am still learning JavaEE so maybe this is a basic question or I am missing something. 顺便说一下,我还在学习JavaEE,所以这可能是一个基本问题,或者我遗漏了一些东西。

When running under a JavaEE container, you should avoid using the JDK's standard Timer feature. 在JavaEE容器下运行时,应避免使用JDK的标准计时器功能。 You should use EJB timers instead; 您应该使用EJB计时器; favour those over any proprietary solution (I think that Work Managers are proprietary to WebLogic). 支持那些超过任何专有解决方案(我认为工作管理器是WebLogic专有的)。

Start here: http://docs.oracle.com/javaee/6/tutorial/doc/bnboy.html 从这里开始: http//docs.oracle.com/javaee/6/tutorial/doc/bnboy.html

Timer timer = new Timer();
timer.schedule(new MyTask(), 1000, 2000);

考虑javax.ejb.Schedule注释

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM