Search code examples
springwebspherespring-batchspring-transactionspropagation

Spring Batch suspend transaction (NOT_SUPPORTED) for tasklet execution on websphere application server


Here is the how our application is configured for Spring batch.

Spring batch and Quartz related tables are configured on a separate instance. Application specific DB instances are different. Application runs on WebSphere Application Server 8.0

We do not want the spring batch transaction to be propagated to tasklet execution. To achieve this is what we have tried, but it does not seem to work. Has anyone faced similar issue? Please suggest on how to proceed.

Transaction is not getting suspended. Spring caches the connection using ConnectionHolder and does not release the connection if it is under a transaction. We do not want the connection to be cached and we want to get a fresh connection from datasource (connection pool) instead of using spring cached connection handle.

<batch:job id="jobId" job-repository="jobRepository">
    <batch:step id="stepId">
        <batch:tasklet ref="taskletId">
            <batch:transaction-attributes propagation="NOT_SUPPORTED" />
        </batch:tasklet>
    </batch:step>
</batch:job>

<bean id="transactionManager" class="org.springframework.transaction.jta.WebSphereUowTransactionManager"/>

Thanks.


Solution

  • Really the best way to handle this is to use a separate, application specific datasource that is not tied to the transaction you're currently a part of. That prevents the connection in use from being part of the transaction in the first place.