Alachisoft.NCache.Common.Threading.ThreadPool Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of nc-common Show documentation
Show all versions of nc-common Show documentation
Internal package of Alachisoft.
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package Alachisoft.NCache.Common.Threading;
import java.util.concurrent.*;
public class ThreadPool {
ExecutorService threadPool = null;
private static ThreadPool instance= null;
private ThreadPool()
{
threadPool= Executors.newCachedThreadPool();
}
public static ThreadPool getInstance() {
if (instance == null) {
instance = new ThreadPool();
}
return instance;
}
public void Stop(boolean shutdownImmediate) {
if (shutdownImmediate) {
threadPool.shutdownNow();
} else {
threadPool.shutdown();
}
instance= null;
}
public void executeTask(Runnable task) {
if (task != null && threadPool != null && !threadPool.isShutdown()) {
threadPool.execute(task);
}
}
public Future submitTask(Runnable task) {
if (task != null && threadPool != null && !threadPool.isShutdown()) {
return threadPool.submit(task);
}
return null;
}
}