Java EE 中有哪些用于定时批处理的工具?
我的雇主刚刚要求我在他们运行的 Java EE WebSphere 应用程序中运行定时批处理。 它应该每天晚上 11:30 运行某个课程。
我对 Java EE 和 WebSphere 服务器(或开发环境中的 tomcat)不太熟悉,我一直在挖掘,但我发现的只是关于 java 计时器类,而不是如何设置它或调用它。
似乎还需要编辑 web.xml 文件。
任何帮助将不胜感激!
My employer just asked me to run a timed batch process in a Java EE WebSphere application they have running. It's supposed to run a certain class at 11:30 pm everyday.
I'm not very familiar with Java EE nor WebSphere server (or tomcat, in the development environment), and I've been digging around but all I've found is about the java timer class but not how to set it or invoke it.
It seems that editing the web.xml file is required as well.
Any help will be appreciated!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(7)
WebSphere 中不支持调度。
如果您使用的是 unix,则可以使用 crontab 来安排对 websphere 应用程序页面的请求。 我想在 Windows 上也可以安排对页面的请求。 向网页发出请求
在我的 crontab 中,我安排每天在 8:45 45 8 * * * GET http://www.domain.com/myBatch?securitykey=verysecret
现在,每天早上都会调用 myBatch servlet,我可以在那里做当时需要做的任何事情。 为了避免其他人调用此页面并启动批处理,我添加了 securitykey 参数。
There is no support for scheduling in WebSphere.
If you are on unix you can use crontab to schedule a request to a page of your websphere application. I suppose on windows there is also a possibility to schedule a request to a page. In my crontab I schedule a request to a webpage each day at 8:45
45 8 * * * GET http://www.domain.com/myBatch?securitykey=verysecret
Now every morning the myBatch servlet is called and there I can do whatever needs to be done at that time. To avoid others calling this page and start the batch, I added the securitykey parameter.
Quartz 是标准 JBoss 4.2.x 发行版的一部分。
这是一个非常好的库,无需太多工作,您也可以定义简单的工作流程。
Quartz is part of the standard JBoss 4.2.x distribution.
And is a really good library, that without much work you can also define simple workflows.
EJB 3.1 将改进计时器服务以及应用程序生命周期挂钩,从而无需使用 servlet 来启动任务而无需用户交互。
这可能会回答问题标题,但对于有关在 websphere 上运行的遗留应用程序(6 个多月前编写的;))的“真正”问题,我建议使用启动 servlet 和 EJB 计时器服务。
J2EE 1.4 (EJB 2.1) 中的计时器服务
对于EJB 3.0(以及尽快推出的 3.1),有一些不错的注释 ;)
我不会介绍另一个 库除非你真的需要它。 计时器服务应该足以每天执行任意工作。
HTH,
马丁
EJB 3.1 will have improved timer services, as well as application lifecycle hooks that remove the need to use servlets to start tasks without user interaction.
This may answer the question title, but for the "real" question concerning a legacy application (written more than 6 months ago ;)) running on websphere I'd recommend to go with the start-up servlet and the EJB timer service.
Timer Service in J2EE 1.4 (EJB 2.1)
For EJB 3.0 (and 3.1 as soon as available), there are some nice annotations ;)
I'd not introduce another library unless you REALLY need it. The timer service should suffice for performing an arbitrary job on a daily basis.
HTH,
Martin
WebSphere 中包含对调度的支持。
是v7.0
http://publib.boulder.ibm.com/infocenter/wasinfo/v7r0/topic/com.ibm.websphere.base.doc/info/aes/ae/welc6tech_sch.html
WAS v6.1
http://publib.boulder.ibm.com/infocenter/wasinfo/v6r1/topic/com.ibm.websphere.base.doc/info/aes/ae/welc6tech_sch.html
There is support for scheduling included in WebSphere.
WAS v7.0
http://publib.boulder.ibm.com/infocenter/wasinfo/v7r0/topic/com.ibm.websphere.base.doc/info/aes/ae/welc6tech_sch.html
WAS v6.1
http://publib.boulder.ibm.com/infocenter/wasinfo/v6r1/topic/com.ibm.websphere.base.doc/info/aes/ae/welc6tech_sch.html
在 web.xml 中,您可以配置一个 servlet 在启动时加载。
语法:
<启动时加载/>
执行此操作,然后在 servlet 的 init 方法中,您可以设置一个 Timer / TimerTask 来执行您需要执行的任何操作。 TimerTasks 类似于线程,只不过您可以安排它们何时运行。
In your web.xml you can configure a servlet to load at startup.
Syntax:
<servlet servlet-name='hello'
servlet-class='test.HelloWorld'>
<load-on-startup/>
</servlet>
Do this, then in the init method in the servlet you can set up a Timer / TimerTask to do whatever it is you need to do. TimerTasks are like Threads except you can schedule them when to run.
在WebSphere 中,您可以使用Scheduler Service 来触发java 类中方法的执行。
调度程序提供了一个用于调度作业执行的日历(类似于 cron),或者您可以开发自己的日历。
以下是 WAS 6.1 文档中描述调度程序的页面的链接:
http ://publib.boulder.ibm.com/infocenter/wasinfo/v6r1/index.jsp
In WebSphere, you can use the Scheduler Service to trigger the execution of a method in a java class.
The scheduler provides a calendar for scheduling the execution of jobs (similar to cron) or you could develop your own.
Here's a link to the page describing the scheduler in the WAS 6.1 documentation:
http://publib.boulder.ibm.com/infocenter/wasinfo/v6r1/index.jsp
您应该查看 OpenSymphony 的开源 Quartz 库。 非常容易使用,非常适合这种事情。
TimerTasks 最适合在未来短时间内运行某些任务。 但对于像这样的大时间范围内的重复执行,Quartz 表现出色。 您甚至可以将即将到来的任务列表保存在持久存储中,例如文件或数据库,因此如果您的应用程序重新启动,即将到来的定时作业也不会丢失。
另外,Spring 框架中有一个很棒的 Quartz 抽象。
You should look at the open-source Quartz library from OpenSymphony. Very easy to use and perfect for this kind of thing.
TimerTasks are best suited for running something in a short time in the future. But for a repeated execution in a large timeframe such as this, Quartz excels. You can even keep your list of upcoming tasks in persistent storage such as a file or database, so upcoming timed jobs are not lost if your application is restarted.
Also, there's a fantastic abstraction for Quartz in the Spring framework.