All Downloads are FREE. Search and download functionalities are using the official Maven repository.

Alachisoft.NCache.Common.Threading.ThreadPool Maven / Gradle / Ivy

There is a newer version: 5.3.3
Show newest version
/*
 * 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;
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy