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!
解决方案
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.