You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by ma...@apache.org on 2010/03/06 11:02:17 UTC
svn commit: r919730 -
/tomcat/trunk/java/org/apache/catalina/core/StandardThreadExecutor.java
Author: markt
Date: Sat Mar 6 10:02:16 2010
New Revision: 919730
URL: http://svn.apache.org/viewvc?rev=919730&view=rev
Log:
Lifecycle refactoring - Executor
The LifecycleState.STARTING event was being fired too early
Modified:
tomcat/trunk/java/org/apache/catalina/core/StandardThreadExecutor.java
Modified: tomcat/trunk/java/org/apache/catalina/core/StandardThreadExecutor.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/core/StandardThreadExecutor.java?rev=919730&r1=919729&r2=919730&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/core/StandardThreadExecutor.java (original)
+++ tomcat/trunk/java/org/apache/catalina/core/StandardThreadExecutor.java Sat Mar 6 10:02:16 2010
@@ -22,14 +22,15 @@
import org.apache.catalina.Executor;
import org.apache.catalina.LifecycleException;
-import org.apache.catalina.LifecycleListener;
-import org.apache.catalina.util.LifecycleSupport;
+import org.apache.catalina.LifecycleState;
+import org.apache.catalina.util.LifecycleBase;
import org.apache.tomcat.util.threads.ResizableExecutor;
import org.apache.tomcat.util.threads.TaskQueue;
import org.apache.tomcat.util.threads.TaskThreadFactory;
import org.apache.tomcat.util.threads.ThreadPoolExecutor;
-public class StandardThreadExecutor implements Executor, ResizableExecutor {
+public class StandardThreadExecutor extends LifecycleBase
+ implements Executor, ResizableExecutor {
// ---------------------------------------------- Properties
/**
@@ -77,8 +78,6 @@
*/
protected int maxQueueSize = Integer.MAX_VALUE;
- private LifecycleSupport lifecycle = new LifecycleSupport(this);
-
private TaskQueue taskqueue = null;
// ---------------------------------------------- Constructors
public StandardThreadExecutor() {
@@ -88,23 +87,40 @@
// ---------------------------------------------- Public Methods
- public void start() throws LifecycleException {
- lifecycle.fireLifecycleEvent(BEFORE_START_EVENT, null);
+
+ /**
+ * Start the component and implement the requirements
+ * of {@link LifecycleBase#startInternal()}.
+ *
+ * @exception LifecycleException if this component detects a fatal error
+ * that prevents this component from being used
+ */
+ @Override
+ protected void startInternal() throws LifecycleException {
+
taskqueue = new TaskQueue(maxQueueSize);
TaskThreadFactory tf = new TaskThreadFactory(namePrefix,daemon,getThreadPriority());
- lifecycle.fireLifecycleEvent(START_EVENT, null);
executor = new ThreadPoolExecutor(getMinSpareThreads(), getMaxThreads(), maxIdleTime, TimeUnit.MILLISECONDS,taskqueue, tf);
taskqueue.setParent(executor);
- lifecycle.fireLifecycleEvent(AFTER_START_EVENT, null);
+
+ setState(LifecycleState.STARTING);
}
-
- public void stop() throws LifecycleException{
- lifecycle.fireLifecycleEvent(BEFORE_STOP_EVENT, null);
- lifecycle.fireLifecycleEvent(STOP_EVENT, null);
+
+
+ /**
+ * Stop the component and implement the requirements
+ * of {@link LifecycleBase#stopInternal()}.
+ *
+ * @exception LifecycleException if this component detects a fatal error
+ * that needs to be reported
+ */
+ @Override
+ protected void stopInternal() throws LifecycleException {
+
+ setState(LifecycleState.STOPPING);
if ( executor != null ) executor.shutdownNow();
executor = null;
taskqueue = null;
- lifecycle.fireLifecycleEvent(AFTER_STOP_EVENT, null);
}
public void execute(Runnable command, long timeout, TimeUnit unit) {
@@ -201,34 +217,6 @@
return maxQueueSize;
}
- /**
- * Add a LifecycleEvent listener to this component.
- *
- * @param listener The listener to add
- */
- public void addLifecycleListener(LifecycleListener listener) {
- lifecycle.addLifecycleListener(listener);
- }
-
-
- /**
- * Get the lifecycle listeners associated with this lifecycle. If this
- * Lifecycle has no listeners registered, a zero-length array is returned.
- */
- public LifecycleListener[] findLifecycleListeners() {
- return lifecycle.findLifecycleListeners();
- }
-
-
- /**
- * Remove a LifecycleEvent listener from this component.
- *
- * @param listener The listener to remove
- */
- public void removeLifecycleListener(LifecycleListener listener) {
- lifecycle.removeLifecycleListener(listener);
- }
-
// Statistics from the thread pool
public int getActiveCount() {
return (executor != null) ? executor.getActiveCount() : 0;
@@ -258,13 +246,12 @@
@Override
public boolean resizePool(int corePoolSize, int maximumPoolSize) {
- if (executor == null) {
+ if (executor == null)
return false;
- } else {
- executor.setCorePoolSize(corePoolSize);
- executor.setMaximumPoolSize(maximumPoolSize);
- return true;
- }
+
+ executor.setCorePoolSize(corePoolSize);
+ executor.setMaximumPoolSize(maximumPoolSize);
+ return true;
}
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org