Replace synchronized blocks and methods with locks

This commit replaces synchronized blocks and methods
that are used frequently or that guard blocking I/O
operations with locks. This is required to prevent
virtual threads pinning, as explained in JEP 444 [1].

Note that synchronized blocks and methods that are used
infrequently (like AutomaticJobRegistrar#start/stop) or
that guard in-memory operations were not replaced as this
is not required, see JEP 444 [1].

Resolves to #4399

---
[1]: https://openjdk.org/jeps/444
This commit is contained in:
Mahmoud Ben Hassine
2023-07-15 08:18:07 +02:00
parent 05168089f1
commit 5bccfed523
11 changed files with 144 additions and 26 deletions

View File

@@ -20,6 +20,8 @@ import java.io.InputStream;
import java.io.ObjectInputStream;
import java.util.Iterator;
import java.util.List;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;
import javax.sql.DataSource;
@@ -50,7 +52,7 @@ public class StagingItemReader<T>
private StepExecution stepExecution;
private final Object lock = new Object();
private final Lock lock = new ReentrantLock();
private volatile boolean initialized = false;
@@ -75,7 +77,8 @@ public class StagingItemReader<T>
private List<Long> retrieveKeys() {
synchronized (lock) {
this.lock.lock();
try {
return jdbcTemplate.query(
@@ -86,6 +89,9 @@ public class StagingItemReader<T>
stepExecution.getJobExecution().getJobId(), StagingItemWriter.NEW);
}
finally {
this.lock.unlock();
}
}