What tools are there for timed batch processes in

2019-05-29 01:31发布

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!

7条回答
聊天终结者
2楼-- · 2019-05-29 01:59

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.

查看更多
ら.Afraid
3楼-- · 2019-05-29 02:04

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.

查看更多
Bombasti
5楼-- · 2019-05-29 02:09

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

查看更多
仙女界的扛把子
6楼-- · 2019-05-29 02:15

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.

查看更多
Juvenile、少年°
7楼-- · 2019-05-29 02:17

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.

查看更多
登录 后发表回答