public class ThreadPoolHandler
{
private ExecutorService executorService;
private ThreadPoolHandler()
{
executorService = Executors.newFixedThreadPool(2);
}
private static class ThreadPoolHandlerFactory
{
private static ThreadPoolHandler threadPoolHandler = new ThreadPoolHandler();
}
public static ThreadPoolHandler getInstance()
{
return ThreadPoolHandlerFactory.threadPoolHandler;
}
public void destroy()
{
if (null != executorService)
executorService.shutdown();
}
public void addTask(Runnable rn)
{
executorService.execute(rn);
}
}