-
Jun 28th, 2012, 05:09 AM
#1
Using JDBCTemplate in ItemWriter is very slow.
Hi,
I am using jdbcTemplate which is inserted into Itemwriter. Below is the configuration. the time it is taking to update 100 records is around 2 mins. But with out Spring batch using simple spring with jdbcTemplate is getting these records updated in less than 20 seconds.
Is there anything I am missing in setting the transaction or anything that is causing this delay in the DB update. Also somewhere I saw that new ApplicationContext is created every time that piece of code was called. I am not sure if that is causing me the problem.
I am using CommandLineJobRunner for running the application.
-----------------------------------
<bean id="jdbcTemplate" class ="org.springframework.jdbc.core.JdbcTemplate">
<constructor-arg index="0" type="javax.sql.DataSource">
<ref local = "datasource" />
</constructor-arg>
</bean>
<bean id="writer" class="com.fileloader.writer.TransactionWriter" >
<property name = "transactionTemplate" >
<ref local = "transactionTemplate" />
</property>
<property name ="jdbcTemplate"><ref bean = "jdbcTemplate" /></property>
</bean>
public void write(final List<? extends TransactionBean> tBeans) throws Exception {
try{
transactionTemplate.execute(new TransactionCallback() {
public Object doInTransaction(TransactionStatus status) {
for (TransactionBean tBean : tBeans) { jdbcTemplate.update(tBean.getSqlString() , tBean.getSqlValues());
}
return null;
}
});
}
catch (Exception e)
{
e.printStackTrace();
}
}
------------
Advanced thanks
Thanks
-
Jul 6th, 2012, 10:20 AM
#2
Two things:
- You should not manage the transaction: SB'll do for you
- performances: you should use the JDBC add batch/execute batch features, instead of doing single-row updates
SB already have all you need: give a try to JdbcBatchItemWriter
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules