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
The following commit(s) were added to refs/heads/main by this push: new e329ceb5c7 Switch to using LongAddr to track request/error count for servlets e329ceb5c7 is described below commit e329ceb5c7aa51c33f036b375e88d7e35cc50706 Author: Mark Thomas <ma...@apache.org> AuthorDate: Tue Jan 24 13:22:34 2023 +0000 Switch to using LongAddr to track request/error count for servlets --- java/org/apache/catalina/core/StandardContext.java | 16 ++++--------- java/org/apache/catalina/core/StandardWrapper.java | 12 ++-------- .../apache/catalina/core/StandardWrapperValve.java | 26 ++++++++-------------- webapps/docs/changelog.xml | 5 +++++ 4 files changed, 20 insertions(+), 39 deletions(-) diff --git a/java/org/apache/catalina/core/StandardContext.java b/java/org/apache/catalina/core/StandardContext.java index e0ca2f97c5..be5d325a72 100644 --- a/java/org/apache/catalina/core/StandardContext.java +++ b/java/org/apache/catalina/core/StandardContext.java @@ -4094,14 +4094,10 @@ public class StandardContext extends ContainerBase implements Context, Notificat * Gets the cumulative request count of all servlets in this StandardContext. * * @return Cumulative request count of all servlets in this StandardContext - * - * @deprecated The return type will change to long in Tomcat 11 onwards. Callers of this method should switch to - * storing the result of calls to this method in a long value rather than an int. */ - @Deprecated - public int getRequestCount() { + public long getRequestCount() { - int result = 0; + long result = 0; Container[] children = findChildren(); if (children != null) { @@ -4117,14 +4113,10 @@ public class StandardContext extends ContainerBase implements Context, Notificat * Gets the cumulative error count of all servlets in this StandardContext. * * @return Cumulative error count of all servlets in this StandardContext - * - * @deprecated The return type will change to long in Tomcat 11 onwards. Callers of this method should switch to - * storing the result of calls to this method in a long value rather than an int. */ - @Deprecated - public int getErrorCount() { + public long getErrorCount() { - int result = 0; + long result = 0; Container[] children = findChildren(); if (children != null) { diff --git a/java/org/apache/catalina/core/StandardWrapper.java b/java/org/apache/catalina/core/StandardWrapper.java index d0d89d3aec..a3006fb496 100644 --- a/java/org/apache/catalina/core/StandardWrapper.java +++ b/java/org/apache/catalina/core/StandardWrapper.java @@ -1178,12 +1178,8 @@ public class StandardWrapper extends ContainerBase implements ServletConfig, Wra * Returns the number of requests processed by the wrapper. * * @return the number of requests processed by the wrapper. - * - * @deprecated The return type will change to long in Tomcat 11 onwards. Callers of this method should switch to - * storing the result of calls to this method in a long value rather than an int. */ - @Deprecated - public int getRequestCount() { + public long getRequestCount() { return swValve.getRequestCount(); } @@ -1191,12 +1187,8 @@ public class StandardWrapper extends ContainerBase implements ServletConfig, Wra * Returns the number of requests processed by the wrapper that resulted in an error. * * @return the number of requests processed by the wrapper that resulted in an error. - * - * @deprecated The return type will change to long in Tomcat 11 onwards. Callers of this method should switch to - * storing the result of calls to this method in a long value rather than an int. */ - @Deprecated - public int getErrorCount() { + public long getErrorCount() { return swValve.getErrorCount(); } diff --git a/java/org/apache/catalina/core/StandardWrapperValve.java b/java/org/apache/catalina/core/StandardWrapperValve.java index 5d2f0f2456..cfed5bd8ce 100644 --- a/java/org/apache/catalina/core/StandardWrapperValve.java +++ b/java/org/apache/catalina/core/StandardWrapperValve.java @@ -18,7 +18,7 @@ package org.apache.catalina.core; import java.io.IOException; -import java.util.concurrent.atomic.AtomicInteger; +import java.util.concurrent.atomic.LongAdder; import jakarta.servlet.DispatcherType; import jakarta.servlet.RequestDispatcher; @@ -66,8 +66,8 @@ final class StandardWrapperValve extends ValveBase { private volatile long processingTime; private volatile long maxTime; private volatile long minTime = Long.MAX_VALUE; - private final AtomicInteger requestCount = new AtomicInteger(0); - private final AtomicInteger errorCount = new AtomicInteger(0); + private final LongAdder requestCount = new LongAdder(); + private final LongAdder errorCount = new LongAdder(); // --------------------------------------------------------- Public Methods @@ -89,7 +89,7 @@ final class StandardWrapperValve extends ValveBase { Throwable throwable = null; // This should be a Request attribute... long t1 = System.currentTimeMillis(); - requestCount.incrementAndGet(); + requestCount.increment(); StandardWrapper wrapper = (StandardWrapper) getContainer(); Servlet servlet = null; Context context = (Context) wrapper.getParent(); @@ -292,30 +292,22 @@ final class StandardWrapperValve extends ValveBase { * Returns the number of requests processed by the associated wrapper. * * @return the number of requests processed by the associated wrapper. - * - * @deprecated The return type will change to long in Tomcat 11 onwards. Callers of this method should switch to - * storing the result of calls to this method in a long value rather than an int. */ - @Deprecated - public int getRequestCount() { - return requestCount.get(); + public long getRequestCount() { + return requestCount.sum(); } /** * Returns the number of requests processed by the associated wrapper that resulted in an error. * * @return the number of requests processed by the associated wrapper that resulted in an error. - * - * @deprecated The return type will change to long in Tomcat 11 onwards. Callers of this method should switch to - * storing the result of calls to this method in a long value rather than an int. */ - @Deprecated - public int getErrorCount() { - return errorCount.get(); + public long getErrorCount() { + return errorCount.sum(); } public void incrementErrorCount() { - errorCount.incrementAndGet(); + errorCount.increment(); } @Override diff --git a/webapps/docs/changelog.xml b/webapps/docs/changelog.xml index 9fba57e37f..ba24331f65 100644 --- a/webapps/docs/changelog.xml +++ b/webapps/docs/changelog.xml @@ -138,6 +138,11 @@ Switch to using the ServiceLoader mechanism to load the custom URL protocol handlers that Tomcat uses. (markt) </update> + <fix> + Switch to using <code>LongAdder</code> rather than + <code>AtomicInteger</code> to track request count and error count for + servlets. (markt) + </fix> </changelog> </subsection> <subsection name="Coyote"> --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org For additional commands, e-mail: dev-h...@tomcat.apache.org