Skip to content

Commit a425d71

Browse files
jhoellerunknown
authored andcommitted
ThreadPoolExecutorFactoryBean exposes "createExecutor" method for custom ThreadPoolExecutor subclasses
Issue: SPR-9435
1 parent 4dde7c4 commit a425d71

File tree

1 file changed

+25
-5
lines changed

1 file changed

+25
-5
lines changed

spring-context/src/main/java/org/springframework/scheduling/concurrent/ThreadPoolExecutorFactoryBean.java

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2012 the original author or authors.
2+
* Copyright 2002-2013 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -126,7 +126,7 @@ public void setQueueCapacity(int queueCapacity) {
126126
* <p>Default is "false", exposing the raw executor as bean reference.
127127
* Switch this flag to "true" to strictly prevent clients from
128128
* modifying the executor's configuration.
129-
* @see java.util.concurrent.Executors#unconfigurableScheduledExecutorService
129+
* @see java.util.concurrent.Executors#unconfigurableExecutorService
130130
*/
131131
public void setExposeUnconfigurableExecutor(boolean exposeUnconfigurableExecutor) {
132132
this.exposeUnconfigurableExecutor = exposeUnconfigurableExecutor;
@@ -137,9 +137,8 @@ protected ExecutorService initializeExecutor(
137137
ThreadFactory threadFactory, RejectedExecutionHandler rejectedExecutionHandler) {
138138

139139
BlockingQueue<Runnable> queue = createQueue(this.queueCapacity);
140-
ThreadPoolExecutor executor = new ThreadPoolExecutor(
141-
this.corePoolSize, this.maxPoolSize, this.keepAliveSeconds, TimeUnit.SECONDS,
142-
queue, threadFactory, rejectedExecutionHandler);
140+
ThreadPoolExecutor executor = createExecutor(this.corePoolSize, this.maxPoolSize,
141+
this.keepAliveSeconds, queue, threadFactory, rejectedExecutionHandler);
143142
if (this.allowCoreThreadTimeOut) {
144143
executor.allowCoreThreadTimeOut(true);
145144
}
@@ -151,6 +150,27 @@ protected ExecutorService initializeExecutor(
151150
return executor;
152151
}
153152

153+
/**
154+
* Create a new instance of {@link ThreadPoolExecutor} or a subclass thereof.
155+
* <p>The default implementation creates a standard {@link ThreadPoolExecutor}.
156+
* Can be overridden to provide custom {@link ThreadPoolExecutor} subclasses.
157+
* @param corePoolSize the specified core pool size
158+
* @param maxPoolSize the specified maximum pool size
159+
* @param keepAliveSeconds the specified keep-alive time in seconds
160+
* @param queue the BlockingQueue to use
161+
* @param threadFactory the ThreadFactory to use
162+
* @param rejectedExecutionHandler the RejectedExecutionHandler to use
163+
* @return a new ThreadPoolExecutor instance
164+
* @see #afterPropertiesSet()
165+
*/
166+
protected ThreadPoolExecutor createExecutor(
167+
int corePoolSize, int maxPoolSize, int keepAliveSeconds, BlockingQueue<Runnable> queue,
168+
ThreadFactory threadFactory, RejectedExecutionHandler rejectedExecutionHandler) {
169+
170+
return new ThreadPoolExecutor(corePoolSize, maxPoolSize,
171+
keepAliveSeconds, TimeUnit.SECONDS, queue, threadFactory, rejectedExecutionHandler);
172+
}
173+
154174
/**
155175
* Create the BlockingQueue to use for the ThreadPoolExecutor.
156176
* <p>A LinkedBlockingQueue instance will be created for a positive

0 commit comments

Comments
 (0)