Results 1 to 2 of 2

Thread: Using JDBCTemplate in ItemWriter is very slow.

  1. #1
    Join Date
    Jun 2012
    Posts
    5

    Default 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

  2. #2

    Default

    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
  •