Search in sources :

Example 1 with LockSupport

use of java.util.concurrent.locks.LockSupport in project hazelcast-jet by hazelcast.

the class TaskletExecutionService method submitCooperativeTasklets.

private void submitCooperativeTasklets(ExecutionTracker executionTracker, ClassLoader jobClassLoader, List<Tasklet> tasklets) {
    ensureThreadsStarted();
    final List<TaskletTracker>[] trackersByThread = new List[cooperativeWorkers.length];
    Arrays.setAll(trackersByThread, i -> new ArrayList());
    for (Tasklet t : tasklets) {
        t.init();
        trackersByThread[cooperativeThreadIndex.getAndUpdate(i -> (i + 1) % trackersByThread.length)].add(new TaskletTracker(t, executionTracker, jobClassLoader));
    }
    for (int i = 0; i < trackersByThread.length; i++) {
        cooperativeWorkers[i].trackers.addAll(trackersByThread[i]);
    }
    Arrays.stream(cooperativeThreadPool).forEach(LockSupport::unpark);
}
Also used : ArrayList(java.util.ArrayList) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) LockSupport(java.util.concurrent.locks.LockSupport) ArrayList(java.util.ArrayList) List(java.util.List) Collectors.toList(java.util.stream.Collectors.toList) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList)

Aggregations

ArrayList (java.util.ArrayList)1 List (java.util.List)1 CopyOnWriteArrayList (java.util.concurrent.CopyOnWriteArrayList)1 LockSupport (java.util.concurrent.locks.LockSupport)1 Collectors.toList (java.util.stream.Collectors.toList)1