java - how to use JdbcTemplate in a multithreaded environment? -


i'm trying use spring jdbctemplate spring's simpleasynctaskexecutor concurrent connections db can made , whole data can inserted related table in smaller amount of time when compared single threaded environment.

i'm using following code, doesn't speed application.

the clue find fact bean "campaignproductdbwriter" constructed once whereas i'm expecting 10 seperate instances created set "throttle-limit" 10 in tasklet.

what doing wrong? or suggestions appreciated.

regards,

<bean id="datasourceproduct"   class="org.springframework.jdbc.datasource.drivermanagerdatasource"   p:driverclassname="${jdbc.driverclassname}" p:url="${jdbc.url.product}"   p:username="${jdbc.username.product}" p:password="${jdbc.password.product}"  />  <bean id="jdbctemplateproduct" class="org.springframework.jdbc.core.jdbctemplate">   <property name="datasource" ref="datasourceproduct" /> </bean>  <bean id="simpletaskexecutor" class="org.springframework.core.task.simpleasynctaskexecutor" >   <property name="concurrencylimit" value="-1" /> </bean>  <batch:job id="samplejob" restartable="true"  incrementer="dynamicjobparameters">                <batch:step id="mapmzlist">     <batch:tasklet allow-start-if-complete="true" task-executor="simpletaskexecutor" throttle-limit="10">                            <batch:chunk reader="campaignproductitemreader" processor="campaignproductprocessor" writer="campaignproductdbwriter" commit-interval="5000"/>             </batch:tasklet>   </batch:step>                  </batch:job>  <bean id="campaignproductdbwriter" class="com.falcon.cc.job.step.campaignproductwriter">   <property name="jdbctemplate" ref="jdbctemplateproduct" /> </bean>   <bean id="campaignproductitemreader" class="com.falcon.cc.job.step.flatfilesynchronizeditemreader" scope="step">       <property name="resource" value="file:#{jobparameters['input.test_file.path']}"/>    <property name="linemapper">     <bean class="org.springframework.batch.item.file.mapping.defaultlinemapper">               <property name="linetokenizer">                <bean class="org.springframework.batch.item.file.transform.delimitedlinetokenizer">           <property name="delimiter" value=";"/>                       <property name="names" value="approvalstatus,validfrom,validto"/>         </bean>       </property>       <property name="fieldsetmapper">         <bean class="com.falcon.cc.mapper.campaignproductfieldsetmapper" />       </property>     </bean>   </property> </bean> 

this not problem spring config, or how you're using jdbctemplate, thin, stateless wrapper around jdbc api.

the obvious likelihood bottleneck database, not code. it's entirely possible running multiple concurrent operations against database no faster doing them 1 @ time.

there several reasons this, such database locking, or lack of raw i/o performance.

when considering using multi-threading improve performance, have sure bottlenecks are. if code isn't bottleneck, making multi-threaded isn't going make things faster.


Comments

Popular posts from this blog

c# - How to set Z index when using WPF DrawingContext? -

razor - Is this a bug in WebMatrix PageData? -

visual c++ - Using relative values in array sorting ( asm ) -