Results 1 to 3 of 3

Thread: JdbcCursorItemReader - Connection

  1. #1

    Thumbs up JdbcCursorItemReader - Connection

    Hi All,
    I have a batch that contain one master job with a tasklet step. Inside the tasklet I will register the job (Considering as child job) and then launch it.
    I don't have any issue in the configuration and running batch, But even though child processing completed successfully the Connection still exists.
    If i check the sql server 2005 activity moniter, there is 2 processes is running.

    <code>
    -- Master Job

    <job id="Batch_ControllerJob"
    restartable="true" xmlns="http://www.springframework.org/schema/batch">

    <step id="BatchExecutor" >
    <tasklet ref="batchExecutor" transaction-manager="transactionManager" />

    </step>
    </job>

    </code>

    From the batchExecutor I will call the child Job in a new thread.

    <code>
    -- Child job

    <job id="Step_List_Item_ControllerJob" restartable="true" xmlns="http://www.springframework.org/schema/batch">
    <step id="Run_Task_List_Item_ControllerStep">
    <tasklet>
    <chunk reader="stepListQueryReader" processor="stepListItemProcessor"
    writer="stepListItemWriter" commit-interval="10" />
    </tasklet>
    </step>
    </job>

    <bean id="stepListQueryReader"
    class="org.springframework.batch.item.database.Jdb cCursorItemReader"
    scope="step">
    <property name="dataSource" ref="dataSource" />
    <property name="rowMapper">
    <bean class="batch.core.mapper.StepListRowMapper" />
    </property>
    <property name="sql" ref="#{jobParameters['stepName']}" />
    </bean>

    </code>

    Once the child job (Step_List_Item_ControllerJob) is finished processing, the stepListQueryReader's cursor should close the connection?
    I have missed any configuration?

    Thanks for your response in advance
    Thanks & Regards,
    Arun Duraisamy

  2. #2
    Join Date
    May 2011
    Location
    New Delhi, India
    Posts
    157

    Default

    The connection might be showing as open if you are using a connection pool/data source. Spring Batch also needs connection to connect to the repository.

  3. #3

    Smile

    Thanks for your reply rishishehrawat.

    My test result for SingleConnectionDataSource and BasicDataSource:

    If I use :
    <code>

    <bean id="dataSource"
    class="org.springframework.jdbc.datasource.SingleC onnectionDataSource"
    destroy-method="close">
    <property name="driverClassName" value="com.microsoft.sqlserver.jdbc.SQLServerDrive r" />
    <property name="url"
    value="jdbc:sqlserver://yyyyyyyy">
    </property>
    <property name="username" value="xx" />
    <property name="password" value="xx" />
    <property name="suppressClose">
    <value>true</value>
    </property>
    </bean>
    </code>

    instead of

    <code>

    <bean id="myDataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">

    </code>

    a single connection is active.

    SingleConnectionDataSource Documentation say that

    <p>This is primarily intended for testing. For example, it enables easy testing
    * outside an application server, for code that expects to work on a DataSource.
    * In contrast to {@link DriverManagerDataSource}, it reuses the same Connection
    * all the time, avoiding excessive creation of physical Connections
    </p>


    Our Batch will run the Same job with different job paramteres in different thread.
    Is this SingleConnectionDataSource will suite for my batch?

    Thanks For Your Reply in advance.
    Thanks & Regards,
    Arun Duraisamy

Posting Permissions

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