Reputation: 398
We have a system that allows an operator to stop a long running Spring Batch job by using the JobExplorer
to get a reference to the JobExecution
and calling stop()
on it. We then have code inside our jobs that use the JobExplorer
to get an up-to-date copy of the JobExecution
to check to see if it has been marked as STOPPING.
Our problem is deadlocks on the metadata tables in Microsoft SQL Server 2016. Each select is doing a shared page lock. Everything I have been able to find about changing the lock level talks about using a hint on the SELECT
statement. But Spring Batch is creating the statement, not our code.
Is there a way to tell Spring Batch to use read-only concurrency when making SELECT
statements? If not, is there some mechanism short of writing our own JobExplorer
to accomplish this?
Upvotes: 0
Views: 704
Reputation: 31600
stop a long running Spring Batch job by using the JobExplorer to get a reference to the JobExecution and calling stop() on it.
JobExecution#stop
will be deprecated in the next minor version 4.3 and removed in the next major version (See https://github.com/spring-projects/spring-batch/issues/1605). The correct way to stop a job execution is to use JobOperator#stop
.
Is there a way to tell Spring Batch to use read-only concurrency when making SELECT statements? If not, is there some mechanism short of writing our own JobExplorer to accomplish this?
There is an open issue to make the job explorer transactional (read-only): https://github.com/spring-projects/spring-batch/issues/1307. In the mean time, you can make the SimpleJobExplorer
transactional (either through AOP or by extending it to add @Transactional(readOnly = true)
on methods).
Upvotes: 1