Page 2 of 2 FirstFirst 12
Results 11 to 13 of 13

Thread: Suggestion for a job design

  1. #11
    Join Date
    Jul 2012
    Posts
    24

    Default

    Thanks a lot! Clear. I think I've solved, since the batch seems to do just what I want!

  2. #12
    Join Date
    Jul 2012
    Posts
    24

    Default

    Just a question: since I use a dataSource for JdbcTemplate, could you tell me how to not create and release the connection to the database for each item being processed? If my file has 3000 lines, I will do getConnection and relase connection to the database 3000 times. At the moment I still don't know how to get the connection at row 1 and release it at row 3000. Is it possible to do that?

    The only class I've found is SingleConnectionDataSource, but I'm still studying how to use it... Maybe it's just sufficient to use such bean instead of BasicDataSource. Isn't it?

    EDIT: actually using the following configuration, the connection is anything but single:
    Code:
    <bean id="dataSource" class="org.springframework.jdbc.datasource.SingleConnectionDataSource">
    	<property name="driverClassName" value="oracle.jdbc.driver.OracleDriver" />
    	<property name="url" value="jdbc:oracle:thin:@localhost:1521:test" />
    	<property name="username" value="USR" />
    	<property name="password" value="PASS" />
    	<property name="suppressClose" value="true"/>
    </bean>
    And the Spring Batch in Action manual suggests this approach to hold a single JDBC connection to the database and reuse for each query.
    Last edited by fbcyborg; Aug 24th, 2012 at 08:37 AM.

  3. #13
    Join Date
    Aug 2006
    Posts
    129

    Default

    use commons dbcp
    Code:
    <bean id="batch-job-data-source" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close"
    		p:url="${db.url}" p:username="${db.username}" 
    		p:password="${db.password}" p:maxIdle="10" p:maxActive="100"
    		p:maxWait="10000" p:validationQuery="${db.validationQuery}" p:testOnBorrow="false"
    		p:testWhileIdle="true" p:timeBetweenEvictionRunsMillis="1200000"
    		p:minEvictableIdleTimeMillis="1800000" p:numTestsPerEvictionRun="5"
    		p:defaultAutoCommit="false"
    		p:driverClassName="${db.driverClassName}" />
    the jdbc batch commit is controlled in the step :
    Code:
    <batch:chunk reader="jdbc-data-input-reader" processor="item-processor" writer="jdbc-data-input-writer" commit-interval="#{jobParameters['commit.interval']}" />

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •