com.github.thorbenkuck.keller.mvp.ThreadPoolCache Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of keller-mvp Show documentation
Show all versions of keller-mvp Show documentation
Keller is a universal base-package
The newest version!
package com.github.thorbenkuck.keller.mvp;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Semaphore;
class ThreadPoolCache {
private static ExecutorService executorService;
private static final Semaphore semaphore = new Semaphore(1);
static ExecutorService getExecutorService() {
return lazyGet();
}
private static ExecutorService lazyGet() {
ExecutorService returnValue;
try {
semaphore.acquire();
if(executorService == null || executorService.isShutdown()) {
executorService = Executors.newCachedThreadPool();
}
returnValue = executorService;
} catch (InterruptedException e) {
e.printStackTrace();
throw new IllegalStateException("Creation of ExecutorService failed!");
} finally {
semaphore.release();
}
return returnValue;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy