Skip to content

Commit

Permalink
new: thread initializers
Browse files Browse the repository at this point in the history
  • Loading branch information
ishland committed Oct 29, 2023
1 parent 00a98c2 commit 9bbd292
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions src/main/java/com/ishland/flowsched/executor/ExecutorManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
import com.ishland.flowsched.structs.DynamicPriorityQueue;
import it.unimi.dsi.fastutil.objects.Object2ReferenceOpenHashMap;

import java.util.ArrayDeque;
import java.util.Queue;
import java.util.function.Consumer;

public class ExecutorManager {

Expand All @@ -20,9 +20,20 @@ public class ExecutorManager {
* @param workerThreadCount the number of worker threads.
*/
public ExecutorManager(int workerThreadCount) {
this(workerThreadCount, thread -> {});
}

/**
* Creates a new executor manager.
*
* @param workerThreadCount the number of worker threads.
* @param threadInitializer the thread initializer.
*/
public ExecutorManager(int workerThreadCount, Consumer<Thread> threadInitializer) {
workerThreads = new WorkerThread[workerThreadCount];
for (int i = 0; i < workerThreadCount; i++) {
final WorkerThread thread = new WorkerThread(this);
threadInitializer.accept(thread);
thread.start();
workerThreads[i] = thread;
}
Expand All @@ -45,7 +56,6 @@ boolean tryLock(Task task) {
}
for (LockToken token : task.lockTokens()) {
assert !this.lockListeners.containsKey(token);
this.lockListeners.put(token, new ArrayDeque<>());
}
return true;
}
Expand Down

0 comments on commit 9bbd292

Please sign in to comment.