introduced a default foreground task executor in ThreadPoolUtils which is used in AbstractSimpleLeaderboardImpl now

Change-Id: I46d039cb23e31bf7cf31598af3eb51b62b7a9520
This commit is contained in:
Axel Uhl committed 2016-08-16 13:14:47 +02:00
1 parent 2ac6151c67
commit 696db21f3a
3 files changed
+34 -2

No files matched your search

@@ -24,6 +24,24 @@ public interface ThreadPoolUtil {
*/
ExecutorService getDefaultBackgroundTaskThreadPoolExecutor();
/**
* Returns a central, default thread pool executor that can be used to schedule foreground tasks. Using this
* centralized copy ensures that when several application modules require such an executor they get a single one
* whose dimensions are chosen such that it does not outperform other system-critical tasks such as garbage
* collection and JITting.
* <p>
*
* The executor will have {@link Thread#NORM_PRIORITY} as its priority, therefore slightly superseding the priority
* of {@link #getDefaultBackgroundTaskThreadPoolExecutor()}, and its threads will all be {@link Thread#setDaemon
* daemon threads}. The task queue is limited by {@link Integer#MAX_VALUE}, so is virtually unbounded, and therefore
* no specific rejection handler is configured.
* <p>
*
* The thread pool uses constant size, so the core size equals the maximum size, and threads will not be terminated
* once created. Its size is calculated using {@link #getReasonableThreadPoolSize()}.
*/
ExecutorService getDefaultForegroundTaskThreadPoolExecutor();
/**
* Returns a new thread pool executor that can be used to schedule background tasks. Normally, clients should use
* {@link #getDefaultBackgroundTaskThreadPoolExecutor()} instead. However, under certain rare circumstances it may
@@ -11,12 +11,17 @@ public class ThreadPoolUtilImpl implements ThreadPoolUtil {
private static final int REASONABLE_THREAD_POOL_SIZE = Math.max(Runtime.getRuntime().availableProcessors()/2, 3);
private final ExecutorService defaultBackgroundTaskThreadPoolExecutor;
private final ExecutorService defaultForegroundTaskThreadPoolExecutor;
public ThreadPoolUtilImpl() {
defaultBackgroundTaskThreadPoolExecutor = new ThreadPoolExecutor(/* corePoolSize */ REASONABLE_THREAD_POOL_SIZE,
/* maximumPoolSize */ REASONABLE_THREAD_POOL_SIZE,
/* keepAliveTime */ 60, TimeUnit.SECONDS,
/* workQueue */ new LinkedBlockingQueue<Runnable>(), new ThreadFactoryWithPriority(Thread.NORM_PRIORITY-1, /* daemon */ true));
defaultForegroundTaskThreadPoolExecutor = new ThreadPoolExecutor(/* corePoolSize */ REASONABLE_THREAD_POOL_SIZE,
/* maximumPoolSize */ REASONABLE_THREAD_POOL_SIZE,
/* keepAliveTime */ 60, TimeUnit.SECONDS,
/* workQueue */ new LinkedBlockingQueue<Runnable>(), new ThreadFactoryWithPriority(Thread.NORM_PRIORITY, /* daemon */ true));
}
@Override
@@ -24,6 +29,11 @@ public class ThreadPoolUtilImpl implements ThreadPoolUtil {
return defaultBackgroundTaskThreadPoolExecutor;
}
@Override
public ExecutorService getDefaultForegroundTaskThreadPoolExecutor() {
return defaultForegroundTaskThreadPoolExecutor;
}
@Override
public ExecutorService createBackgroundTaskThreadPoolExecutor() {
return new ThreadPoolExecutor(/* corePoolSize */ REASONABLE_THREAD_POOL_SIZE,