Announcement Announcement Module
Collapse
No announcement yet.
StaxEventItemWriter throws NullPointerException Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • StaxEventItemWriter throws NullPointerException

    Hi,
    i am using StaxEventItemWriter in my code to transfer the data from the database to physical files.

    The beans confiuration as below
    !-- Archiving the Data from the PWHH database to physical files and then deleting the Files -->
    <batch:job id="archiveToDiskJob" restartable="true">
    <batch:step id="archivingStep" >
    <batch:tasklet transaction-manager="histTransactionManager">
    <batch:chunk
    commit-interval="${archivingStep.commitInterval}"
    retry-limit="1"
    reader="archivingItemReader"
    writer="archivingItemWriter"
    throttle-limit="1"
    task-executor="jobLauncherTaskExecutor"
    skip-limit="1">
    <batch:retryable-exception-classes>
    org.springframework.dao.DeadlockLoserDataAccessExc eption
    </batch:retryable-exception-classes>
    <batch:skippable-exception-classes>
    org.springframework.batch.core.step.item.FaultTole rantChunkProvider
    </batch:skippable-exception-classes>
    <batch:streams>
    <batch:stream ref="archivingStaxEventItemWriter"/>
    </batch:streams>
    </batch:chunk>
    <batch:listeners>
    <batch:listener ref="genericItemFailureListener" />
    </batch:listeners>
    </batch:tasklet>
    </batch:step>
    </batch:job>

    <!--Reading the PWHH database to Archive -->
    <bean id="archivingItemReader" class="com.te.pwh.services.history.jobs.Historical izationItemReader" scope="step">
    <property name="jdbcTemplate">
    <bean class="org.springframework.jdbc.core.JdbcTemplate" >
    <property name="dataSource" ref="pwhHistoryDatasource" />
    </bean>
    </property>
    <property name="paymentFileDao" ref="historicPaymentFileDao" />
    <property name="numFileRows" value="${historicalizationStep.fileFetchRowSize}" />
    </bean>

    <!--Translating data from PWHH database to physical File -->
    <bean name="archivingItemWriter" class="org.springframework.batch.item.support.Comp ositeItemWriter" scope="step">
    <property name="delegates">
    <list>
    <ref bean="archivingStaxEventItemWriter" />
    <bean class="com.te.pwh.services.history.jobs.DeletePaym entFileItemWriter">
    <property name="historicalizationPaymentFileDao" ref="historyHistoricalizationPaymentFileDao" />
    </bean>
    </list>
    </property>
    </bean>

    <!--Writing data into physical file -->
    <bean id="archivingStaxEventItemWriter" class="org.springframework.batch.item.xml.StaxEven tItemWriter" scope="step">
    <property name="resource" ref="archiveFile" />
    <property name="rootTagName" value="Root" />
    <property name="overwriteOutput" value="false" />
    <property name="marshaller" ref="archivingFilesMarshaller" />
    </bean>

    <bean id="archiveFile" class="org.springframework.core.io.FileSystemResou rce" scope="step">
    <constructor-arg type="java.io.File" value="${archiveFile.filePattern}#{stepExecutionCo ntext['archvingFile']}" />
    </bean>

    <bean id="archivingFilesMarshaller" class="org.springframework.oxm.xstream.XStreamMars haller">
    <property name="aliases">
    <util:map id="aliases" map-class="java.util.HashMap">
    <entry key="Tpwpayfi" value="com.te.pwh.hibernate.Tpwpayfi" />
    </util:map>
    </property>
    </bean>

    But after some time i am getting the NullPointerException. Stack strace is below

    Help is appreciated .

    /10/2010 20:44:53,484 [WorkManager.PwhWorkManager : 0] ERROR org.springframework.batch.core.step.AbstractStep - Encountered an error executing the step
    java.lang.NullPointerException at org.springframework.batch.repeat.support.RepeatTem plate.canContinue(RepeatTemplate.java:391)

    at org.springframework.batch.repeat.support.TaskExecu torRepeatTemplate.waitForResults(TaskExecutorRepea tTemplate.java:188)
    at org.springframework.batch.repeat.support.RepeatTem plate.executeInternal(RepeatTemplate.java:231)
    at org.springframework.batch.repeat.support.RepeatTem plate.iterate(RepeatTemplate.java:143)
    at org.springframework.batch.core.step.tasklet.Taskle tStep.doExecute(TaskletStep.java:242)
    at org.springframework.batch.core.step.AbstractStep.e xecute(AbstractStep.java:198)
    at org.springframework.batch.core.job.AbstractJob.han dleStep(AbstractJob.java:348)
    at org.springframework.batch.core.job.flow.FlowJob.ac cess$100(FlowJob.java:43)
    at org.springframework.batch.core.job.flow.FlowJob$Jo bFlowExecutor.executeStep(FlowJob.java:135)
    at org.springframework.batch.core.job.flow.support.st ate.StepState.handle(StepState.java:60)
    at org.springframework.batch.core.job.flow.support.Si mpleFlow.resume(SimpleFlow.java:144)
    at org.springframework.batch.core.job.flow.support.Si mpleFlow.start(SimpleFlow.java:124)
    at org.springframework.batch.core.job.flow.FlowJob.do Execute(FlowJob.java:103)
    at org.springframework.batch.core.job.AbstractJob.exe cute(AbstractJob.java:250)
    at org.springframework.batch.core.launch.support.Simp leJobLauncher$1.run(SimpleJobLauncher.java:110)
    at org.springframework.core.task.SyncTaskExecutor.exe cute(SyncTaskExecutor.java:49)
    at org.springframework.batch.core.launch.support.Simp leJobLauncher.run(SimpleJobLauncher.java:105)
    at com.te.pwh.services.history.jobs.QuartzBatchLaunch erJob.executeJob(QuartzBatchLauncherJob.java:221)
    at com.te.pwh.services.history.jobs.QuartzBatchLaunch erJob.executeInternal(QuartzBatchLauncherJob.java: 79)
    at org.springframework.scheduling.quartz.QuartzJobBea n.execute(QuartzJobBean.java:86)
    at org.quartz.core.JobRunShell.run(JobRunShell.java:2 02)
    at org.springframework.scheduling.commonj.DelegatingW ork.run(DelegatingWork.java:61)
    at com.ibm.ws.asynchbeans.J2EEContext.run(J2EEContext .java:1112)
    at com.ibm.ws.asynchbeans.WorkWithExecutionContextImp l.go(WorkWithExecutionContextImpl.java:195)
    at com.ibm.ws.asynchbeans.CJWorkItemImpl.run(CJWorkIt emImpl.java:187)
    at com.ibm.ws.util.ThreadPool$Worker.run(ThreadPool.j ava:1498)

  • #2
    The NPE is nothing to do with the ItemWriter is it? What version of Spring Batch are you using?

    Using a task executor in your step with throttle-limit=1 is pointless. And the StaxEventItemWriter is not thread safe (the Javadocs say it is not), so using a task executor at all is probably a mistake. If you remove those settings does it work?

    There's another potential error in your configuration: I doubt if it is ever correct to use a different transaction manager for your step than the job.

    (Please use [code][/code] tags to post code and stack traces.)

    P.S. posting duplicates won't help get you an answer - it might just irritate people.

    Comment


    • #3
      out of Memory error

      Thanks a quick reply.

      Yes, i agree with you NPE is noothing to do with ItemWriter.


      I am using the spring batch version 2.0.4.RELEASE.

      I have removed the task executor from the step, i have also removed the transaction manager from the step.

      I have tested with above setting and got the Out of Memory error

      Plasese help for this .

      <code> <batch:job id="archiveToDiskJob" restartable="true">
      <batch:step id="archivingStep">
      <batch:tasklet>
      <batch:chunk
      commit-interval="${archivingStep.commitInterval}"
      retry-limit="1"
      reader="archivingItemReader"
      writer="archivingItemWriter"
      throttle-limit="1"
      skip-limit="1">
      <batch:retryable-exception-classes>
      org.springframework.dao.DeadlockLoserDataAccessExc eption
      </batch:retryable-exception-classes>
      <batch:skippable-exception-classes>
      org.springframework.batch.core.step.item.FaultTole rantChunkProvider
      </batch:skippable-exception-classes>
      <batch:streams>
      <batch:stream ref="archivingStaxEventItemWriter"/>
      </batch:streams>
      </batch:chunk>
      <batch:listeners>
      <batch:listener ref="genericItemFailureListener" />
      </batch:listeners>
      </batch:tasklet>
      </batch:step>

      </batch:job>

      <!--Reading the PWHH database to Archive -->
      <bean id="archivingItemReader" class="com.te.pwh.services.history.jobs.Historical izationItemReader" scope="step">
      <property name="jdbcTemplate">
      <bean class="org.springframework.jdbc.core.JdbcTemplate" >
      <property name="dataSource" ref="pwhHistoryDatasource" />
      </bean>
      </property>
      <property name="paymentFileDao" ref="historicPaymentFileDao" />
      <property name="numFileRows" value="${historicalizationStep.fileFetchRowSize}" />
      </bean>

      <!--Translating data from PWHH database to physical File -->
      <bean name="archivingItemWriter" class="org.springframework.batch.item.support.Comp ositeItemWriter">
      <property name="delegates">
      <list>
      <ref bean="archivingStaxEventItemWriter" />
      <bean class="com.te.pwh.services.history.jobs.DeletePaym entFileItemWriter">
      <property name="historicalizationPaymentFileDao" ref="historyHistoricalizationPaymentFileDao" />
      </bean>
      </list>
      </property>
      </bean>

      <!--Writing data into physical file -->
      <bean id="archivingStaxEventItemWriter" class="org.springframework.batch.item.xml.StaxEven tItemWriter">
      <property name="resource" ref="archiveFile" />
      <property name="rootTagName" value="Root" />
      <property name="overwriteOutput" value="false" />
      <property name="marshaller" ref="archivingFilesMarshaller" />
      </bean>

      <bean id="archiveFile" class="org.springframework.core.io.FileSystemResou rce" scope="step">
      <constructor-arg type="java.io.File" value="${archiveFile.filePattern}#{jobParameters['archvingFile']}" />
      </bean>

      <bean id="archivingFilesMarshaller" class="org.springframework.oxm.xstream.XStreamMars haller">
      <property name="aliases">
      <util:map id="aliases" map-class="java.util.HashMap">
      <entry key="Tpwpayfi" value="com.te.pwh.hibernate.Tpwpayfi" />
      <entry key="Tpwpaygr" value="com.te.pwh.hibernate.Tpwpaygr" />
      <entry key="Tpwpayfi" value="com.te.pwh.hibernate.Tpwpamsg" />
      </util:map>
      </property>
      <property name="mode" value="1004"/>
      </bean>
      </code>

      Comment


      • #4
        A stack trace might help. What's your commit interval?

        (Please use [code][/code] tags to post code and stack traces.)

        Comment

        Working...
        X