This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Spring and the fly likes org.springframework.batch.core.repository.JobExecutionAlreadyRunningException Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Frameworks » Spring
Bookmark "org.springframework.batch.core.repository.JobExecutionAlreadyRunningException" Watch "org.springframework.batch.core.repository.JobExecutionAlreadyRunningException" New topic
Author

org.springframework.batch.core.repository.JobExecutionAlreadyRunningException

Jay Abrahm
Ranch Hand

Joined: May 28, 2008
Posts: 183
I have the following xml configured from the Spring Batch examples to run every 10 seconds but I get an error while starting up. I also have logs configured at InfiniteLoopReader and InfiniteLoopWriter but it never hits those classes and yes it does make entries into the batch table.
How do I reconfigure this ?


Saifuddin Merchant
Ranch Hand

Joined: Feb 08, 2009
Posts: 597

You need to pass in different parameters at start-up for the job to run.

If the job was previously launched with teh same JobParameters and completed successfully, then it is an error to restart it. An ad-hoc request needs to be distinguished from previous runs by adding a unique job parameter. In either case a new JobExecution is created and stored to monitor this execution of the JobInstance.


Cheers - Sam.
Twisters - The new age Java Quiz || My Blog
Jay Abrahm
Ranch Hand

Joined: May 28, 2008
Posts: 183
Sam Mercs wrote:You need to pass in different parameters at start-up for the job to run.


Is there an example you could point me to or could you post a quick code snippet on what parameter needs to be passed. If it needs to be unique can I just pass the time in milliseconds ? Not sure how it can be done though ...
Saifuddin Merchant
Ranch Hand

Joined: Feb 08, 2009
Posts: 597

You have not mentioned how you are running the job, are you trying to run is as a Junit test? are you running it from the command line? do you have it scheduled to run?

In all case, you need to pass in job parameters, you can get all the details - http://static.springsource.org/spring-batch/reference/html/configureJob.html - 4.4. Running a Job in this section of the document.

Here is the gist,

If your using the command like job runner (shell script)

dateParam=date '+%m%d%y_%H%M%S'
java CommandLineJobRunner JOB_CONFIG.xml JOB_NAME timestamp=$dateParam

If you using Junit test & JobLauncherTestUtils, from the Javadoc...
It should be noted that using any of the methods that don't contain JobParameters in their signature, will result in one being created with the current system time as a parameter. This will ensure restartability when no parameters are provided.

If you are passing in param you need to add a unique param...



Jay Abrahm
Ranch Hand

Joined: May 28, 2008
Posts: 183
I am running the job using quartz. The intention is to trigger some service calls within the ear to do some plumbing tasks every hour.

I wasn't sure on how to pass the job parameters in my case but when I increased the time gap between the tasks and also removed the Thread sleep in the samples, it wasn't spitting out JobExecutionAlreadyRunningException.

And it now triggers the job properly
com.test.JobLauncherDetails executeInternal Quartz trigger firing with Spring Batch jobName=footballJob
com.test.JobLauncherDetails executeInternal Quartz trigger firing with Spring Batch jobName=footballJob
com.test.JobLauncherDetails executeInternal Quartz trigger firing with Spring Batch jobName=footballJob
......

But now I don't see any entries in the Spring batch table, it doesn't seem to hit the reader/writer classes even though it isn't throwing any exceptions.

One more question, I was able to trigger my batch using Quarts example @ Quartz example. I keep hearing that Spring Batch is the ideal way to do this but can someone explain why using Batch is a better bet than using quartz in my scenario.
Saifuddin Merchant
Ranch Hand

Joined: Feb 08, 2009
Posts: 597

What does your datasource and transactionManager beans refer to. Could you add the configuration for those. If they are configured correctly, it should write to the database ...
Jay Abrahm
Ranch Hand

Joined: May 28, 2008
Posts: 183
Here goes...
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: org.springframework.batch.core.repository.JobExecutionAlreadyRunningException
 
Similar Threads
Help with Spring Batch (Newbie)
Running a batch
Simple Spring Batch
Using Spring and Quartz
Quartz Cron Expression Help