
org.pcj.internal.WorkerPoolExecutor Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of pcj Show documentation
Show all versions of pcj Show documentation
PCJ is Java library for parallel computing in Java. It is based on the PGAS (Partitioned Global Address Space) paradigm. It allows for easy implementation in Java of any parallel algorithm. PCJ application can be run on laptop, workstation, cluster and HPC system including large supercomputers.
The newest version!
/*
* Copyright (c) 2011-2019, PCJ Library, Marek Nowicki
* All rights reserved.
*
* Licensed under New BSD License (3-clause license).
*
* See the file "LICENSE" for the full license governing this code.
*/
package org.pcj.internal;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.RejectedExecutionHandler;
import java.util.concurrent.ThreadFactory;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;
/**
* @author Marek Nowicki ([email protected])
*/
public class WorkerPoolExecutor extends ThreadPoolExecutor {
public WorkerPoolExecutor(int poolSize,
ThreadGroup threadGroup, String threadNamePrefix,
BlockingQueue workQueue,
RejectedExecutionHandler rejectedExecutionHandler) {
super(poolSize, poolSize, Long.MAX_VALUE, TimeUnit.NANOSECONDS,
workQueue,
new WorkerThreadFactory(threadGroup, threadNamePrefix),
rejectedExecutionHandler);
prestartAllCoreThreads();
}
private static class WorkerThreadFactory implements ThreadFactory {
private final ThreadGroup threadGroup;
private final String threadNamePrefix;
private final AtomicInteger counter = new AtomicInteger(0);
private WorkerThreadFactory(ThreadGroup threadGroup, String threadNamePrefix) {
this.threadGroup = threadGroup;
this.threadNamePrefix = threadNamePrefix;
}
@Override
public Thread newThread(Runnable r) {
return new Thread(threadGroup, r, threadNamePrefix + counter.getAndIncrement());
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy