Author: remm Date: Thu Nov 8 15:49:57 2018 New Revision: 1846164 URL: http://svn.apache.org/viewvc?rev=1846164&view=rev Log: Add monitors to the two other scheduled tasks, and simplify a bit wherever possible.
Modified: tomcat/trunk/java/org/apache/catalina/core/ContainerBase.java tomcat/trunk/java/org/apache/catalina/tribes/group/GroupChannel.java tomcat/trunk/java/org/apache/coyote/AbstractProtocol.java tomcat/trunk/java/org/apache/coyote/LocalStrings.properties Modified: tomcat/trunk/java/org/apache/catalina/core/ContainerBase.java URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/core/ContainerBase.java?rev=1846164&r1=1846163&r2=1846164&view=diff ============================================================================== --- tomcat/trunk/java/org/apache/catalina/core/ContainerBase.java (original) +++ tomcat/trunk/java/org/apache/catalina/core/ContainerBase.java Thu Nov 8 15:49:57 2018 @@ -958,6 +958,7 @@ public abstract class ContainerBase exte // Stop our thread if (monitorFuture != null) { monitorFuture.cancel(true); + monitorFuture = null; } threadStop(); Modified: tomcat/trunk/java/org/apache/catalina/tribes/group/GroupChannel.java URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/tribes/group/GroupChannel.java?rev=1846164&r1=1846163&r2=1846164&view=diff ============================================================================== --- tomcat/trunk/java/org/apache/catalina/tribes/group/GroupChannel.java (original) +++ tomcat/trunk/java/org/apache/catalina/tribes/group/GroupChannel.java Thu Nov 8 15:49:57 2018 @@ -22,6 +22,7 @@ import java.io.Serializable; import java.util.Iterator; import java.util.List; import java.util.concurrent.CopyOnWriteArrayList; +import java.util.concurrent.ExecutionException; import java.util.concurrent.ScheduledExecutorService; import java.util.concurrent.ScheduledFuture; import java.util.concurrent.ScheduledThreadPoolExecutor; @@ -79,14 +80,15 @@ public class GroupChannel extends Channe /** * If <code>heartbeat == true</code> then how often do we want this - * heartbeat to run. default is one minute + * heartbeat to run. The default value is 5000 milliseconds. */ - protected long heartbeatSleeptime = 5*1000;//every 5 seconds + protected long heartbeatSleeptime = 5*1000; /** * Internal heartbeat future */ protected ScheduledFuture<?> heartbeatFuture = null; + protected ScheduledFuture<?> monitorFuture; /** * The <code>ChannelCoordinator</code> coordinates the bottom layer components:<br> @@ -477,9 +479,30 @@ public class GroupChannel extends Channe ownExecutor = true; } super.start(svc); - if (heartbeatFuture == null && heartbeat) { - heartbeatFuture = utilityExecutor.scheduleWithFixedDelay - (new HeartbeatRunnable(), heartbeatSleeptime, heartbeatSleeptime, TimeUnit.MILLISECONDS); + startHeartbeat(); + monitorFuture = utilityExecutor.scheduleWithFixedDelay( + new Runnable() { + @Override + public void run() { + startHeartbeat(); + } + }, 60, 60, TimeUnit.SECONDS); + } + + protected void startHeartbeat() { + if (heartbeat && (heartbeatFuture == null || (heartbeatFuture != null && heartbeatFuture.isDone()))) { + if (heartbeatFuture != null && heartbeatFuture.isDone()) { + if (heartbeatFuture != null && heartbeatFuture.isDone()) { + // There was an error executing the scheduled task, get it and log it + try { + heartbeatFuture.get(); + } catch (InterruptedException | ExecutionException e) { + log.error(sm.getString("groupChannel.unable.sendHeartbeat"), e); + } + } + } + heartbeatFuture = utilityExecutor.scheduleWithFixedDelay(new HeartbeatRunnable(), + heartbeatSleeptime, heartbeatSleeptime, TimeUnit.MILLISECONDS); } } @@ -491,6 +514,10 @@ public class GroupChannel extends Channe */ @Override public synchronized void stop(int svc) throws ChannelException { + if (monitorFuture != null) { + monitorFuture.cancel(true); + monitorFuture = null; + } if (heartbeatFuture != null) { heartbeatFuture.cancel(true); heartbeatFuture = null; @@ -804,11 +831,7 @@ public class GroupChannel extends Channe public class HeartbeatRunnable implements Runnable { @Override public void run() { - try { - heartbeat(); - } catch (Exception x) { - log.error(sm.getString("groupChannel.unable.sendHeartbeat"), x); - } + heartbeat(); } } Modified: tomcat/trunk/java/org/apache/coyote/AbstractProtocol.java URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/coyote/AbstractProtocol.java?rev=1846164&r1=1846163&r2=1846164&view=diff ============================================================================== --- tomcat/trunk/java/org/apache/coyote/AbstractProtocol.java (original) +++ tomcat/trunk/java/org/apache/coyote/AbstractProtocol.java Thu Nov 8 15:49:57 2018 @@ -22,6 +22,7 @@ import java.util.Collections; import java.util.Map; import java.util.Set; import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.ExecutionException; import java.util.concurrent.Executor; import java.util.concurrent.ScheduledExecutorService; import java.util.concurrent.ScheduledFuture; @@ -97,6 +98,7 @@ public abstract class AbstractProtocol<S * Controller for the async timeout scheduling. */ private ScheduledFuture<?> asyncTimeoutFuture = null; + private ScheduledFuture<?> monitorFuture; public AbstractProtocol(AbstractEndpoint<S,?> endpoint) { this.endpoint = endpoint; @@ -565,34 +567,46 @@ public abstract class AbstractProtocol<S endpoint.start(); startAsyncTimeout(); + monitorFuture = getUtilityExecutor().scheduleWithFixedDelay( + new Runnable() { + @Override + public void run() { + if (!isPaused()) { + startAsyncTimeout(); + } + } + }, 60, 60, TimeUnit.SECONDS); } protected void startAsyncTimeout() { - if (asyncTimeoutFuture != null) { - return; - } - asyncTimeoutFuture = getUtilityExecutor().scheduleWithFixedDelay( - new Runnable() { - @Override - public void run() { - if (!endpoint.isPaused()) { + if (asyncTimeoutFuture == null || (asyncTimeoutFuture != null && asyncTimeoutFuture.isDone())) { + if (asyncTimeoutFuture != null && asyncTimeoutFuture.isDone()) { + // There was an error executing the scheduled task, get it and log it + try { + asyncTimeoutFuture.get(); + } catch (InterruptedException | ExecutionException e) { + getLog().error(sm.getString("abstractProtocolHandler.asyncTimeoutError"), e); + } + } + asyncTimeoutFuture = getUtilityExecutor().scheduleAtFixedRate( + new Runnable() { + @Override + public void run() { long now = System.currentTimeMillis(); for (Processor processor : waitingProcessors) { processor.timeoutAsync(now); } } - } - - }, 1, 1, TimeUnit.SECONDS); + }, 1, 1, TimeUnit.SECONDS); + } } protected void stopAsyncTimeout() { - if (asyncTimeoutFuture == null) { - return; + if (asyncTimeoutFuture != null) { + asyncTimeoutFuture.cancel(false); + asyncTimeoutFuture = null; } - asyncTimeoutFuture.cancel(false); - asyncTimeoutFuture = null; } @Override @@ -629,6 +643,10 @@ public abstract class AbstractProtocol<S logPortOffset(); } + if (monitorFuture != null) { + monitorFuture.cancel(true); + monitorFuture = null; + } stopAsyncTimeout(); // Timeout any pending async request for (Processor processor : waitingProcessors) { Modified: tomcat/trunk/java/org/apache/coyote/LocalStrings.properties URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/coyote/LocalStrings.properties?rev=1846164&r1=1846163&r2=1846164&view=diff ============================================================================== --- tomcat/trunk/java/org/apache/coyote/LocalStrings.properties [UTF-8] (original) +++ tomcat/trunk/java/org/apache/coyote/LocalStrings.properties [UTF-8] Thu Nov 8 15:49:57 2018 @@ -42,6 +42,7 @@ abstractProtocolHandler.pause=Pausing Pr abstractProtocolHandler.resume=Resuming ProtocolHandler [{0}] abstractProtocolHandler.stop=Stopping ProtocolHandler [{0}] abstractProtocolHandler.destroy=Destroying ProtocolHandler [{0}] +abstractProtocolHandler.asyncTimeoutError=Error processing async timeouts asyncStateMachine.invalidAsyncState=Calling [{0}] is not valid for a request with Async state [{1}] --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org For additional commands, e-mail: dev-h...@tomcat.apache.org