Now I am able to use the DB repository.
When I run the same job more than once I am getting the below exception in the spring batch framework.
Code:
2011-03-28 11:49:21,606 [main] DEBUG - Returning JDBC Connection to DataSource
2011-03-28 11:49:21,606 [main] ERROR - Job Terminated in error: A job execution for this job is already running: JobInstance: id=7, JobParameters=[{status=start, time=new}], Job=[emailBroadcastjob]
org.springframework.batch.core.repository.JobExecutionAlreadyRunningException: A job execution for this job is already running: JobInstance: id=7, JobParameters=[{status=start, time=new}], Job=[emailBroadcastjob]
at org.springframework.batch.core.repository.support.SimpleJobRepository.createJobExecution(SimpleJobRepository.java:112)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:307)
at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:182)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:149)
at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:106)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:204)
at $Proxy0.createJobExecution(Unknown Source)
at org.springframework.batch.core.launch.support.SimpleJobLauncher.run(SimpleJobLauncher.java:98)
at org.springframework.batch.core.launch.support.CommandLineJobRunner.start(CommandLineJobRunner.java:291)
at org.springframework.batch.core.launch.support.CommandLineJobRunner.main(CommandLineJobRunner.java:448)
2011-03-28 11:49:21,606 [main] INFO - Closing org.springframework.context.support.ClassPathXmlApplicationContext@1d009b4: display name [org.springframework.context.support.ClassPathXmlApplicationContext@1d009b4]; startup date [Mon Mar 28 11:49:19 PDT 2011]; root of context hierarchy
2011-03-28 11:49:21,606 [main] INFO - Destroying singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@1d1e730: defining beans [jobRepository-dataSource,jobRepository-transactionManager,jobRepository,jobLauncher,emailBroadcast,org.springframework.batch.core.scope.internalStepScope,org.springframework.beans.factory.config.CustomEditorConfigurer,org.springframework.batch.core.configuration.xml.CoreNamespacePostProcessor,step0,emailBroadcastjob,lazyBindingProxy.emailBroadcast]; root of factory hierarchy
This exception is occuring before it enters into the developer code. Now I need to catch this exception in the below code. Please let me know the sample code
Code:
public RepeatStatus execute(StepContribution arg0, ChunkContext arg1) throws JobExecutionAlreadyRunningException
{
logger.debug("Starting Point--->");
System.out.print(message);
try{
System.out.println("Status--->" + getStatus());
initialize();
if(!(getStatus().trim().equals("stops12"))){
List<BroabcastEmailBo> emailList = getEmailList();
logger.debug("List from Email list count-->" + emailList.size());
logger.debug("Ending Point--->");
return RepeatStatus.CONTINUABLE;
}
else{
logger.debug("Stopping the job-------->Start");
Set<Long> list = jobOperator.getRunningExecutions("emailBroadcastjob");
jobOperator.stop(list.iterator().next());
logger.debug("Stopping the job-------->End");
return RepeatStatus.FINISHED;
}
}
catch(JobExecutionAlreadyRunningException e){
logger.debug("JOb is already running---->");
}
catch(Exception e2){
}
if(getStatus().trim().equals("stops")){
return RepeatStatus.CONTINUABLE;
}else{
return RepeatStatus.FINISHED;
}
}
Here is the command line argument (through Eclipse)
Code:
-stop broadCastEmailBatchJob.xml emailBroadcastjob status=stops