What tools are there for timed batch processes in Java EE?

只谈情不闲聊 提交于 2019-12-22 12:44:09

问题


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!


回答1:


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.




回答2:


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




回答3:


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




回答4:


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.




回答5:


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.




回答6:


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.




回答7:


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



来源:https://stackoverflow.com/questions/78194/what-tools-are-there-for-timed-batch-processes-in-java-ee

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!