Skip to content

Commit

Permalink
Use caller runs policy of default thread pool #2021
Browse files Browse the repository at this point in the history
  • Loading branch information
pditommaso committed May 2, 2021
1 parent 7c22888 commit 48b4e8e
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@ class CustomPoolFactory implements PoolFactory {
def type = property(NXF_POOL_TYPE, 'default')
switch (type) {
case 'default':
int poolSize = Runtime.runtime.availableProcessors() +1
int maxThreads = property(NXF_MAX_THREADS, 1000) as int
return CustomThreadPool.defaultPool(poolSize, maxThreads)

case 'legacy':
return new ResizeablePool(true, 1)

case 'sync':
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,19 @@ static Pool unboundedPool(int maxThreads) {

}

static Pool defaultPool(int poolSize, int maxThreads) {
log.debug(String.format("Creating default thread pool > poolSzie: %s; maxThreads: %s", poolSize, maxThreads));

return new CustomThreadPool(
new ThreadPoolExecutor(
poolSize,
maxThreads,
KEEP_ALIVE_TIME,
TimeUnit.SECONDS,
new SynchronousQueue<Runnable>(),
newDaemonThreadFactory(),
new ThreadPoolExecutor.CallerRunsPolicy()) );
}

static Pool synchronousPool(int maxThreads) {
log.debug(String.format("Creating synchronous thread pool > maxThread: %s", maxThreads));
Expand Down

0 comments on commit 48b4e8e

Please sign in to comment.