4

My team has written an application which we've decided needs to run a process, we'll say about once a day, as long as the application is being used. I've never done anything like this in Java before so am hoping to get a better idea of how I'd design a solution.

Initially, I've been going through the Oracle 'Overview of Batch Processing' tutorial and trying to create a working example of a batch process. However, I got far enough along in the tutorial and read this line:

Starting a Batch Job from a Servlet - Note that the mere presence of a job XML file or other batch artifacts (such as ItemReader) doesn't mean that a batch job is automatically started when the application is deployed. A batch job must be initiated explicitly, say, from a servlet or from an Enterprise JavaBeans (EJB) timer or an EJB business method.

So it would appear that the functionality that I'm looking at does not necessarily entail a continuous process and has to be initiated manually.

Our initial thoughts on what we wanted to accomplish was to have a 'batch job' initiate a service which contained our business logic at least once a day. So I wonder:

  1. Is continuous processing something I should be able to accomplish with the batch processing api I'm looking at?
  2. If so, how does this commonly work?
  3. If not, how do Java developers typically handle this type of problem from a high level?
3

What you are looking to create already exists: look around for Java cron libraries. You can set up a crontab similar to the Unix daemon which invokes Java classes at the intervals you choose as long as your program is running.

Rather than focusing on the batch aspect of the task, focus on the timing aspect. Processing a batch of records is conceptually easier than ensuring your program runs at specific times, and thankfully that part is already done by someone else.

| improve this answer | |
  • Thanks for the reply. I've included the Sauron Software cron4j library into my application and plan to invoke it from a web service. – Canadian Coder Jul 7 '15 at 14:41
  • After some more consideration, we're using the same library and will allow it to be managed via service interface, but we've also implemented a ServletContextListener which will initiate and destroy the scheduler on server startup and shutdown. – Canadian Coder Jul 9 '15 at 20:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.