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 2024/04/19 18:34:47 UTC
(tomcat) 04/06: Refactor to specify acceptor stop wait time in ms rather than s
This is an automated email from the ASF dual-hosted git repository.
markt pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/tomcat.git
commit ef2e8f9c0639a247e68c304a587a5e8b12f8bc3c
Author: Mark Thomas <ma...@apache.org>
AuthorDate: Fri Apr 19 18:04:36 2024 +0100
Refactor to specify acceptor stop wait time in ms rather than s
---
java/org/apache/tomcat/util/net/AbstractEndpoint.java | 2 +-
java/org/apache/tomcat/util/net/Acceptor.java | 12 ++++++++++--
java/org/apache/tomcat/util/net/Nio2Endpoint.java | 6 +++---
java/org/apache/tomcat/util/net/NioEndpoint.java | 2 +-
4 files changed, 15 insertions(+), 7 deletions(-)
diff --git a/java/org/apache/tomcat/util/net/AbstractEndpoint.java b/java/org/apache/tomcat/util/net/AbstractEndpoint.java
index c3a5ee523d..4da1e460cb 100644
--- a/java/org/apache/tomcat/util/net/AbstractEndpoint.java
+++ b/java/org/apache/tomcat/util/net/AbstractEndpoint.java
@@ -1661,7 +1661,7 @@ public abstract class AbstractEndpoint<S,U> {
public final void closeServerSocketGraceful() {
if (bindState == BindState.BOUND_ON_START) {
// Stop accepting new connections
- acceptor.stop(-1);
+ acceptor.stopMillis(-1);
// Release locks that may be preventing the acceptor from stopping
releaseConnectionLatch();
unlockAccept();
diff --git a/java/org/apache/tomcat/util/net/Acceptor.java b/java/org/apache/tomcat/util/net/Acceptor.java
index b1083b292a..d8deb8cb26 100644
--- a/java/org/apache/tomcat/util/net/Acceptor.java
+++ b/java/org/apache/tomcat/util/net/Acceptor.java
@@ -171,12 +171,20 @@ public class Acceptor<U> implements Runnable {
*
* @param waitSeconds The time to wait in seconds. Use a value less than
* zero for no wait.
+ *
+ * @deprecated Unused. Will be remove in Tomcat 11 onwards.
*/
+ @Deprecated
public void stop(int waitSeconds) {
+ stopMillis(waitSeconds * 1000);
+ }
+
+
+ public void stopMillis(int waitMilliseconds) {
stopCalled = true;
- if (waitSeconds > 0) {
+ if (waitMilliseconds > 0) {
try {
- if (!stopLatch.await(waitSeconds, TimeUnit.SECONDS)) {
+ if (!stopLatch.await(waitMilliseconds, TimeUnit.MILLISECONDS)) {
log.warn(sm.getString("acceptor.stop.fail", getThreadName()));
}
} catch (InterruptedException e) {
diff --git a/java/org/apache/tomcat/util/net/Nio2Endpoint.java b/java/org/apache/tomcat/util/net/Nio2Endpoint.java
index 6aba831e9d..7e1fbd77b0 100644
--- a/java/org/apache/tomcat/util/net/Nio2Endpoint.java
+++ b/java/org/apache/tomcat/util/net/Nio2Endpoint.java
@@ -199,7 +199,7 @@ public class Nio2Endpoint extends AbstractNetworkChannelEndpoint<Nio2Channel,Asy
}
if (running) {
running = false;
- acceptor.stop(10);
+ acceptor.stopMillis(10);
// Use the executor to avoid binding the main thread if something bad
// occurs and unbind will also wait for a bit for it to complete
getExecutor().execute(() -> {
@@ -440,11 +440,11 @@ public class Nio2Endpoint extends AbstractNetworkChannelEndpoint<Nio2Channel,Asy
/**
* Signals the Acceptor to stop.
*
- * @param waitSeconds Ignored for NIO2.
+ * @param waitMilliseconds Ignored for NIO2.
*
*/
@Override
- public void stop(int waitSeconds) {
+ public void stopMillis(int waitMilliseconds) {
acceptor.state = AcceptorState.ENDED;
}
diff --git a/java/org/apache/tomcat/util/net/NioEndpoint.java b/java/org/apache/tomcat/util/net/NioEndpoint.java
index 78d52aa08b..e949b11df4 100644
--- a/java/org/apache/tomcat/util/net/NioEndpoint.java
+++ b/java/org/apache/tomcat/util/net/NioEndpoint.java
@@ -297,7 +297,7 @@ public class NioEndpoint extends AbstractNetworkChannelEndpoint<NioChannel,Socke
}
if (running) {
running = false;
- acceptor.stop(10);
+ acceptor.stopMillis(10000);
if (poller != null) {
poller.destroy();
poller = null;
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org