java - DB Connection Leak in Item Reader when using AsyncTaskExecutor -


in spring batch job have developed using asynctaskexecutor, allow parallel processing @ step level. have concurrency limit set 5. use jdbccursoritemreader pick-up input records need process. jdbccursoritemreader configured pick connections connection pool. on job execution have noticed job aborts due exhaustion of connections in pool, leading believe jdbccursoritemreader not releasing connections connection pool. suggestion?

below batch xml

<?xml version="1.0" encoding="utf-8"?> <beans:beans xmlns="http://www.springframework.org/schema/batch"     xmlns:beans="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/xmlschema-instance"     xmlns:util="http://www.springframework.org/schema/util"     xsi:schemalocation="         http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd         http://www.springframework.org/schema/batch http://www.springframework.org/schema/batch/spring-batch-2.1.xsd         http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd">      <beans:import resource="../launch-context.xml" />      <beans:bean id="wsstudentitemreader"         class="org.springframework.batch.item.database.jdbccursoritemreader"             scope="step">         <beans:property name="datasource" ref="rptds" />         <beans:property name="sql"             value="select * students batch_id=?" />         <beans:property name="preparedstatementsetter">             <beans:bean class="com.test.batchdtsetter"                 autowire="byname">                 <beans:property name="batchid" value="#{jobparameters[batchid]}" />              </beans:bean>         </beans:property>         <beans:property name="rowmapper" ref="wsrowmapper" />     </beans:bean>    <beans:bean id="outputwriter"         class="org.springframework.batch.item.support.classifiercompositeitemwriter">         <beans:property name="classifier" ref="writerclassifier" >               </beans:property>         </beans:bean>    <beans:bean id="writerclassifier"     class="com.test.writerclassifier">     <beans:property name="codefailwriter" ref="failjdbcbatchitemwriter" />     <beans:property name="codepasswriter" ref="passjdbcbatchitemwriter"></beans:property> </beans:bean>      <beans:bean id="failjdbcbatchitemwriter"         class="org.springframework.batch.item.database.jdbcbatchitemwriter">         <beans:property name="datasource" ref="rptds" />         <beans:property name="sql"             value="delete students batch_id=?" />         <beans:property name="itempreparedstatementsetter" ref="failstatussetter" />     </beans:bean>  <beans:bean id="failstatussetter" class="com.test.failstatussetter" />      <beans:bean id="passjdbcbatchitemwriter"         class="com.test.passbatchitemwriter">     </beans:bean>      <beans:bean id="wslistnr"         class="com.test.wsbatchlistnr">         <beans:property name="datasource" ref="rptds" />     </beans:bean>       <beans:bean id="wsrowmapper" class="com.test.wsreqmapper" />     <beans:bean id="wsreqprcsr"           class="com.test.wsreqproc">          <beans:property name="datasource" ref="rptds" />     </beans:bean>     <beans:bean id="wsreqprepstmtsetter" class="com.test.wsstudentsetter" />      <step id="initiatestep">         <tasklet ref="initiatesteptask" />     </step>     <step id="wsstudentgenstep">         <tasklet task-executor="taskexecutor">             <chunk reader="wsstudentitemreader" processor="wsreqprcsr"                 writer="outputwriter" commit-interval="4" skip-limit="20">                 <skippable-exception-classes>                     <include class="java.lang.exception" />                 </skippable-exception-classes>             </chunk>             <listeners>                  <listener ref="wslistnr" />             </listeners>                     </tasklet>     </step>     <job id="wsstudent">         <step id="wsstudentfilegenintialstep" parent="initiatestep"             next="wsstudentfilegenstep" />         <step id="wsstudentfilegenstep" parent="wsstudentgenstep" />     </job>       <beans:bean id="initiatesteptask" class="com.test.initializer"         scope="step">     </beans:bean>      <beans:bean id="taskexecutor"        class="org.springframework.core.task.simpleasynctaskexecutor">        <beans:property name="concurrencylimit" value="2"/>    </beans:bean>  </beans:beans> 

config.xml

<?xml version="1.0" encoding="utf-8"?> <beans:beans xmlns:xsi="http://www.w3.org/2001/xmlschema-instance"     xmlns:batch="http://www.springframework.org/schema/batch"     xmlns:context="http://www.springframework.org/schema/context"     xmlns:jdbc="http://www.springframework.org/schema/jdbc" xmlns:beans="http://www.springframework.org/schema/beans"     xmlns:p="http://www.springframework.org/schema/p" xmlns:cache="http://www.springframework.org/schema/cache"     xsi:schemalocation="         http://www.springframework.org/schema/batch http://www.springframework.org/schema/batch/spring-batch-2.1.xsd         http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc-3.0.xsd         http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd         http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd         http://www.springframework.org/schema/cache http://www.springframework.org/schema/cache/spring-cache.xsd">      <context:component-scan base-package="com.test" />     <context:property-placeholder location="classpath:batch.properties" />          <beans:bean id="websiteds"     class="org.springframework.jndi.jndiobjectfactorybean">     <beans:property name="jndiname" value="java:jboss/datasources/websiteds" />     <beans:property name="lookuponstartup" value="false" />     <beans:property name="cache" value="true" />      <beans:property name="proxyinterface" value="javax.sql.datasource" /> </beans:bean>  <beans:bean id="rptds"     class="org.springframework.jndi.jndiobjectfactorybean">     <beans:property name="jndiname" value="java:jboss/datasources/reportingds" />     <beans:property name="lookuponstartup" value="false" />     <beans:property name="cache" value="true" />     <beans:property name="proxyinterface" value="javax.sql.datasource" /> </beans:bean>       <beans:bean id="transactionmanager"         class="org.springframework.jdbc.datasource.datasourcetransactionmanager"         lazy-init="true">         <beans:property name="datasource" ref="rptds" />     </beans:bean>       <beans:bean id="jobrepository"         class="org.springframework.batch.core.repository.support.jobrepositoryfactorybean"         p:databasetype="db2" p:transactionmanager-ref="transactionmanager"         p:datasource-ref="batchds" p:isolation-level-for-create="isolation_repeatable_read" />       <beans:bean id="joblauncher"          class="org.springframework.batch.core.launch.support.simplejoblauncher">         <beans:property name="jobrepository" ref="jobrepository" />      </beans:bean>      <beans:bean id="joboperator"         class="org.springframework.batch.core.launch.support.simplejoboperator"         p:joblauncher-ref="joblauncher" p:jobexplorer-ref="jobexplorer"         p:jobrepository-ref="jobrepository" p:jobregistry-ref="jobregistry" />      <beans:bean id="jobexplorer"         class="org.springframework.batch.core.explore.support.jobexplorerfactorybean"         p:datasource-ref="batchds" />      <beans:bean id="jobregistry"         class="org.springframework.batch.core.configuration.support.mapjobregistry" />     <beans:bean         class="org.springframework.batch.core.configuration.support.jobregistrybeanpostprocessor">         <beans:property name="jobregistry" ref="jobregistry" />     </beans:bean>       <beans:bean id="completionpolicy" class="org.springframework.batch.repeat.policy.defaultresultcompletionpolicy"/>    </beans:beans> 

also refer, simpleasynctaskexecutor trying read record after completion of processing, both issues might related

the issue resolved using jdbcpagingitemreader.

also refer: simpleasynctaskexecutor trying read record after completion of processing

thanks @michaelpralow


Comments

Popular posts from this blog

linux - Does gcc have any options to add version info in ELF binary file? -

android - send complex objects as post php java -

charts - What graph/dashboard product is facebook using in Dashboard: PUE & WUE -