Skip to content

Commit 7d875ba

Browse files
author
Dwivedi
committed
Added API in Operation queue to add custom executor
1 parent c58c3ab commit 7d875ba

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

src/com/kryonite/modules/operations/OperationQueue.java

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ public class OperationQueue {
1414
private long maxExecutionTime = -1;
1515
private int maxConcurrentOperations = 0;
1616
private ExecutorService executor = null;
17+
private boolean terminateExecutorAutomatically = true;
1718
private boolean autoFinishOperationsOnCompletion = false;
1819
private OperationList operationList = new OperationList();
1920

@@ -34,6 +35,15 @@ public OperationQueue(int maxConcurrentOperations) {
3435
setMaxConcurrentOperationsCount(maxConcurrentOperations);
3536
}
3637

38+
/**
39+
* Initializes operation queue with a custom executor.
40+
* @param customExecutor
41+
*/
42+
public OperationQueue(ExecutorService customExecutor) {
43+
this.executor = customExecutor;
44+
terminateExecutorAutomatically = false;
45+
}
46+
3747
/**
3848
* Adds the specified operation to the queue and begins it's execution provided all its dependencies are satisfied.
3949
* @param operation
@@ -121,7 +131,7 @@ void executeOperation(Operation operation) {
121131
synchronized void notifyOperationComplete(Operation operation) {
122132
operationList.removeOperation(operation);
123133

124-
if (operationList.isEmpty()) {
134+
if (operationList.isEmpty() && terminateExecutorAutomatically) {
125135
executor.shutdownNow();
126136
}
127137
}
@@ -136,4 +146,4 @@ private void trackOperation(Operation operation) {
136146
private synchronized void initExecutor() {
137147
this.executor = Executors.newFixedThreadPool(maxConcurrentOperations);
138148
}
139-
}
149+
}

0 commit comments

Comments
 (0)