ASF Bugzilla – Attachment 28687 Details for
Bug 52996
Please backport r723889 from trunk to have MaxQueueSize attribute for Executor available in Tomcat 6
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
Remember
[x]
|
Forgot Password
Login:
[x]
[patch]
Backport of r723889 without changes to the Executor interface to Tomcat 6.0.x trunk
r723889_v2.diff (text/plain), 3.90 KB, created by
Ruediger Pluem
on 2012-04-27 12:37:23 UTC
(
hide
)
Description:
Backport of r723889 without changes to the Executor interface to Tomcat 6.0.x trunk
Filename:
MIME Type:
Creator:
Ruediger Pluem
Created:
2012-04-27 12:37:23 UTC
Size:
3.90 KB
patch
obsolete
>Index: java/org/apache/catalina/core/StandardThreadExecutor.java >=================================================================== >--- java/org/apache/catalina/core/StandardThreadExecutor.java (revision 1331390) >+++ java/org/apache/catalina/core/StandardThreadExecutor.java (working copy) >@@ -33,20 +33,44 @@ > public class StandardThreadExecutor implements Executor { > > // ---------------------------------------------- Properties >+ /** >+ * Default thread priority >+ */ > protected int threadPriority = Thread.NORM_PRIORITY; > >+ /** >+ * Run threads in daemon or non-daemon state >+ */ > protected boolean daemon = true; > >+ /** >+ * Default name prefix for the thread name >+ */ > protected String namePrefix = "tomcat-exec-"; > >+ /** >+ * max number of threads >+ */ > protected int maxThreads = 200; > >+ /** >+ * min number of threads >+ */ > protected int minSpareThreads = 25; > >+ /** >+ * idle time in milliseconds >+ */ > protected int maxIdleTime = 60000; > >+ /** >+ * The executor we use for this component >+ */ > protected ThreadPoolExecutor executor = null; > >+ /** >+ * the name of this thread pool >+ */ > protected String name; > > /** >@@ -54,6 +78,11 @@ > */ > protected AtomicInteger submittedTasksCount; > >+ /** >+ * The maximum number of elements that can queue up before we reject them >+ */ >+ protected int maxQueueSize = Integer.MAX_VALUE; >+ > private LifecycleSupport lifecycle = new LifecycleSupport(this); > // ---------------------------------------------- Constructors > public StandardThreadExecutor() { >@@ -65,7 +94,7 @@ > // ---------------------------------------------- Public Methods > public void start() throws LifecycleException { > lifecycle.fireLifecycleEvent(BEFORE_START_EVENT, null); >- TaskQueue taskqueue = new TaskQueue(); >+ TaskQueue taskqueue = new TaskQueue(maxQueueSize); > TaskThreadFactory tf = new TaskThreadFactory(namePrefix); > lifecycle.fireLifecycleEvent(START_EVENT, null); > executor = new ThreadPoolExecutor(getMinSpareThreads(), getMaxThreads(), maxIdleTime, TimeUnit.MILLISECONDS,taskqueue, tf) { >@@ -100,7 +129,7 @@ > //there could have been contention around the queue > if ( !( (TaskQueue) executor.getQueue()).force(command) ) { > submittedTasksCount.decrementAndGet(); >- throw new RejectedExecutionException(); >+ throw new RejectedExecutionException("Work queue full."); > } > } > } else throw new IllegalStateException("StandardThreadPool not started."); >@@ -172,6 +201,14 @@ > this.name = name; > } > >+ public void setMaxQueueSize(int size) { >+ this.maxQueueSize = size; >+ } >+ >+ public int getMaxQueueSize() { >+ return maxQueueSize; >+ } >+ > /** > * Add a LifecycleEvent listener to this component. > * >@@ -233,8 +270,8 @@ > super(); > } > >- public TaskQueue(int initialCapacity) { >- super(initialCapacity); >+ public TaskQueue(int capacity) { >+ super(capacity); > } > > public TaskQueue(Collection<? extends Runnable> c) { >@@ -250,6 +287,11 @@ > return super.offer(o); //forces the item onto the queue, to be used if the task is rejected > } > >+ public boolean force(Runnable o, long timeout, TimeUnit unit) throws InterruptedException { >+ if ( parent.isShutdown() ) throw new RejectedExecutionException("Executor not running, can't force a command into the queue"); >+ return super.offer(o,timeout,unit); //forces the item onto the queue, to be used if the task is rejected >+ } >+ > public boolean offer(Runnable o) { > //we can't do any checks > if (parent==null) return super.offer(o);
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 52996
:
28514
| 28687 |
28905
|
28907