Announcement Announcement Module
Collapse
No announcement yet.
Getting java.lang.IllegalStateException while closing CompositeItemStream. Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Getting java.lang.IllegalStateException while closing CompositeItemStream.

    Hi,
    I am getting follwoing exception while closing outptu stream

    Code:
    java.lang.IllegalStateException: Already value [true] for key [org.springframework.batch.support.transaction.TransactionAwareBufferedWriter.CLOSE_KEY.1397773136] bound to thread [main]
    	at org.springframework.transaction.support.TransactionSynchronizationManager.bindResource(TransactionSynchronizationManager.java:179)
    	at org.springframework.batch.support.transaction.TransactionAwareBufferedWriter.close(TransactionAwareBufferedWriter.java:140)
    	at org.springframework.batch.item.file.FlatFileItemWriter$OutputState.close(FlatFileItemWriter.java:430)
    	at org.springframework.batch.item.file.FlatFileItemWriter.close(FlatFileItemWriter.java:250)
    	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:48)
    	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    	at java.lang.reflect.Method.invoke(Method.java:600)
    	at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:309)
    	at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:183)
    	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:150)
    	at org.springframework.aop.support.DelegatingIntroductionInterceptor.doProceed(DelegatingIntroductionInterceptor.java:131)
    	at org.springframework.aop.support.DelegatingIntroductionInterceptor.invoke(DelegatingIntroductionInterceptor.java:119)
    	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
    	at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:202)
    	at $Proxy6.close(Unknown Source)
    	at org.springframework.batch.item.support.CompositeItemStream.close(CompositeItemStream.java:86)
    	at com.aa.ta.cbbatch.taxlotsplitprocessor.ProcessorTasklet.close(ProcessorTasklet.java:223)
    	at com.aa.ta.cbbatch.taxlotsplitprocessor.ProcessorTasklet.execute(ProcessorTasklet.java:153)
    	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:48)
    	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    	at java.lang.reflect.Method.invoke(Method.java:600)
    	at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:309)
    	at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:183)
    	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:150)
    	at org.springframework.aop.support.DelegatingIntroductionInterceptor.doProceed(DelegatingIntroductionInterceptor.java:131)
    	at org.springframework.aop.support.DelegatingIntroductionInterceptor.invoke(DelegatingIntroductionInterceptor.java:119)
    	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
    	at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:202)
    	at $Proxy1.execute(Unknown Source)
    	at org.springframework.batch.core.step.tasklet.TaskletStep$ChunkTransactionCallback.doInTransaction(TaskletStep.java:360)
    	at org.springframework.transaction.support.TransactionTemplate.execute(TransactionTemplate.java:130)
    	at org.springframework.batch.core.step.tasklet.TaskletStep$2.doInChunkContext(TaskletStep.java:262)
    	at org.springframework.batch.core.scope.context.StepContextRepeatCallback.doInIteration(StepContextRepeatCallback.java:76)
    	at org.springframework.batch.repeat.support.RepeatTemplate.getNextResult(RepeatTemplate.java:367)
    	at org.springframework.batch.repeat.support.RepeatTemplate.executeInternal(RepeatTemplate.java:214)
    	at org.springframework.batch.repeat.support.RepeatTemplate.iterate(RepeatTemplate.java:143)
    	at org.springframework.batch.core.step.tasklet.TaskletStep.doExecute(TaskletStep.java:248)
    	at org.springframework.batch.core.step.AbstractStep.execute(AbstractStep.java:195)
    	at org.springframework.batch.core.job.SimpleStepHandler.handleStep(SimpleStepHandler.java:135)
    	at org.springframework.batch.core.job.flow.JobFlowExecutor.executeStep(JobFlowExecutor.java:61)
    	at org.springframework.batch.core.job.flow.support.state.StepState.handle(StepState.java:60)
    	at org.springframework.batch.core.job.flow.support.SimpleFlow.resume(SimpleFlow.java:144)
    	at org.springframework.batch.core.job.flow.support.SimpleFlow.start(SimpleFlow.java:124)
    	at org.springframework.batch.core.job.flow.FlowJob.doExecute(FlowJob.java:135)
    	at org.springframework.batch.core.job.AbstractJob.execute(AbstractJob.java:281)
    	at org.springframework.batch.core.launch.support.SimpleJobLauncher$1.run(SimpleJobLauncher.java:120)
    	at org.springframework.core.task.SyncTaskExecutor.execute(SyncTaskExecutor.java:48)
    	at org.springframework.batch.core.launch.support.SimpleJobLauncher.run(SimpleJobLauncher.java:114)
    	at org.springframework.batch.core.launch.support.CommandLineJobRunner.start(CommandLineJobRunner.java:322)
    	at org.springframework.batch.core.launch.support.CommandLineJobRunner.main(CommandLineJobRunner.java:525)
    Code :
    Code:
    public class ProcessorTasklet implements Tasklet, StepExecutionListener {
    	//Reader
    	private ItemReader<InputVO> readerFileDelegate;
    
    	//Writer
    	private ItemWriter<Rec1VO> OutputFile1;
    	private ItemWriter<Rec2VO> OutputFile2;
    	private ItemWriter<Rec3VO> OutputFile3;
    	private ItemWriter<Rec4VO> OutputFile4;
    	
    	private CompositeItemStream streams;
    
    	public RepeatStatus execute(StepContribution contribution, ChunkContext chunkContext) throws Exception {
    		open(chunkContext);
    		.
    		.
    		.
    		//Read from file
    		//BUSINESS LOGIC
    		//Write to file
    		.
    		.
    		.
    		close();
    	}
    
    
    	private void open(ChunkContext chunkContext){
    		streams = new CompositeItemStream();
    		//register reader/writer stream with tasklet execution context to open file stream		
    		streams.register((ItemStream)readerFileDelegate);
    		streams.register((ItemStream)OutputFile1);
    		streams.register((ItemStream)OutputFile2);
    		streams.register((ItemStream)OutputFile3);
    		streams.register((ItemStream)OutputFile4);
    
    		//open registered reader/writer stream
    		streams.open(chunkContext.getStepContext().getStepExecution().getExecutionContext());
    	}
    	private void close(){
    		//close registered reader/writer stream
    		streams.close();
    	}
    We run the job daily but we are getting this exception sometime only not sure why. Most of the time job ran sucessfully without any exception so i am doubtful if there is any issue with code.

    Can anyone please check and let me know whats the issue?

    Thanks in advance !!

  • #2
    it seems a racing condition, please make streams object as synchronized.
    if it still do not resolve problem. please share your XML config file, specific to tasklet.

    Comment


    • #3
      I dont think so that will help as i am using CompositeItemStream() and all methods of this class used synchronised on streams object.
      Can you please let me know if there is any other way?

      Comment


      • #4
        Why are you trying to re-implement chunk based processing in your Tasklet and not using the framework to handle stream registration, calling the ItemReader, etc?

        Comment

        Working...
        X