
org.snapscript.common.thread.ThreadPool Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of snap-all Show documentation
Show all versions of snap-all Show documentation
Dynamic scripting for the JVM
The newest version!
package org.snapscript.common.thread;
import static java.util.concurrent.TimeUnit.SECONDS;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.Executor;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadFactory;
import java.util.concurrent.ThreadPoolExecutor;
public class ThreadPool implements Executor {
private final BlockingQueue queue;
private final ThreadFactory factory;
private final Executor executor;
public ThreadPool() {
this(1);
}
public ThreadPool(int core) {
this(core, 0);
}
public ThreadPool(int core, int stack) {
this(core, core, stack);
}
public ThreadPool(int core, int maximum, int stack) {
this.queue = new LinkedBlockingQueue();
this.factory = new ThreadBuilder(true, stack);
this.executor = new ThreadPoolExecutor(core, maximum, 60L, SECONDS, queue, factory);
}
@Override
public void execute(Runnable command) {
executor.execute(command);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy