Sign up ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free.

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?
share|improve this question

2 Answers 2

up vote 3 down vote accepted

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.

share|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 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 at 20:42

We use bmap4j for batches in Java EE. Although its sometimes a bit complicated it does everything we need: bmap4j

share|improve this answer
    
Maybe, you can improve your answer by saying how bmap4j answers the specific questions of the questioner. –  Benjamin Rogge Jul 7 at 8:28

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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