mirror of
https://github.com/eclipse-sailing-analytics/sailing-analytics.git
synced 2026-10-20 11:10:00 +00:00
introduced a default foreground task executor in ThreadPoolUtils which is used in AbstractSimpleLeaderboardImpl now
Change-Id: I46d039cb23e31bf7cf31598af3eb51b62b7a9520
This commit is contained in:
1 parent
2ac6151c67
commit
696db21f3a
3 files changed
+34
-2
No files matched your search
+6
-2
@@ -152,13 +152,17 @@ public abstract class AbstractSimpleLeaderboardImpl implements Leaderboard, Race
|
||||
private transient Set<CacheInvalidationListener> cacheInvalidationListeners;
|
||||
|
||||
private static final ExecutorService executor = ThreadPoolUtil.INSTANCE.getDefaultBackgroundTaskThreadPoolExecutor();
|
||||
|
||||
/**
|
||||
* This executor needs to be a different one than {@link #executor} because the tasks run by {@link #executor}
|
||||
* can depend on the results of the tasks run by {@link #raceDetailsExecutor}, and an {@link Executor} doesn't
|
||||
* move a task that is blocked by waiting for another {@link FutureTask} to the side but blocks permanently,
|
||||
* ending in a deadlock (one that cannot easily be detected by the Eclipse debugger either).
|
||||
* ending in a deadlock (one that cannot easily be detected by the Eclipse debugger either). Using the default
|
||||
* foreground executor ensures slightly higher priority than for the {@link #executor}, ensuring that these tasks
|
||||
* are preferred over the {@link #executor} tasks which may be waiting for the completion of the tasks submitted
|
||||
* to this excutor.
|
||||
*/
|
||||
private final static ExecutorService raceDetailsExecutor = ThreadPoolUtil.INSTANCE.createBackgroundTaskThreadPoolExecutor();
|
||||
private final static ExecutorService raceDetailsExecutor = ThreadPoolUtil.INSTANCE.getDefaultForegroundTaskThreadPoolExecutor();
|
||||
|
||||
private transient LiveLeaderboardUpdater liveLeaderboardUpdater;
|
||||
|
||||
|
||||
@@ -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,
|
||||
|
||||
Reference in new issue
Block a user