Java – How to Implement Continuous Batch Processing

java

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?

Best Answer

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.

Related Topic