mirror of
https://github.com/eclipse-sailing-analytics/sailing-analytics.git
synced 2026-10-08 13:20:57 +00:00
Changed the unfinished instructions counter handling
A ReentrantReadWriteLock is now used instead of synchronized methods
This commit is contained in:
1 parent
b6726c4cc4
commit
1ddacd3946
1 file changed
+21
-6
+21
-6
@@ -8,6 +8,7 @@ import java.util.concurrent.ExecutionException;
|
||||
import java.util.concurrent.Executor;
|
||||
import java.util.concurrent.FutureTask;
|
||||
import java.util.concurrent.RunnableFuture;
|
||||
import java.util.concurrent.locks.ReentrantReadWriteLock;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
@@ -117,16 +118,30 @@ public abstract class AbstractPartitioningParallelProcessor<InputType, WorkingTy
|
||||
*/
|
||||
private class UnfinishedInstructionsCounter {
|
||||
|
||||
private final ReentrantReadWriteLock instructionsAmountLock;
|
||||
private int unfinishedInstructionsAmount;
|
||||
|
||||
//TODO replace synchronized with ReentrantReadWriteLock
|
||||
public synchronized void increment() {
|
||||
unfinishedInstructionsAmount++;
|
||||
public UnfinishedInstructionsCounter() {
|
||||
instructionsAmountLock = new ReentrantReadWriteLock();
|
||||
}
|
||||
|
||||
public synchronized void decrement() {
|
||||
unfinishedInstructionsAmount--;
|
||||
unfinishedInstructionsAmount = Math.max(0, unfinishedInstructionsAmount);
|
||||
public void increment() {
|
||||
instructionsAmountLock.writeLock().lock();
|
||||
try {
|
||||
unfinishedInstructionsAmount++;
|
||||
} finally {
|
||||
instructionsAmountLock.writeLock().unlock();
|
||||
}
|
||||
}
|
||||
|
||||
public void decrement() {
|
||||
instructionsAmountLock.writeLock().lock();
|
||||
try {
|
||||
unfinishedInstructionsAmount--;
|
||||
unfinishedInstructionsAmount = Math.max(0, unfinishedInstructionsAmount);
|
||||
} finally {
|
||||
instructionsAmountLock.writeLock().unlock();
|
||||
}
|
||||
}
|
||||
|
||||
public int getUnfinishedInstructionsAmount() {
|
||||
|
||||
Reference in new issue
Block a user