Announcement Announcement Module
No announcement yet.
Using JDBCTemplate in ItemWriter is very slow. Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • Using JDBCTemplate in ItemWriter is very slow.


    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" />

    <bean id="writer" class="com.fileloader.writer.TransactionWriter" >
    <property name = "transactionTemplate" >
    <ref local = "transactionTemplate" />
    <property name ="jdbcTemplate"><ref bean = "jdbcTemplate" /></property>

    public void write(final List<? extends TransactionBean> tBeans) throws Exception {

    transactionTemplate.execute(new TransactionCallback() {
    public Object doInTransaction(TransactionStatus status) {
    for (TransactionBean tBean : tBeans) { jdbcTemplate.update(tBean.getSqlString() , tBean.getSqlValues());
    return null;
    catch (Exception e)


    Advanced thanks


  • #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