This is an automated email from the ASF dual-hosted git repository.

markt pushed a commit to branch 9.0.x
in repository https://gitbox.apache.org/repos/asf/tomcat.git


The following commit(s) were added to refs/heads/9.0.x by this push:
     new 834ae5c51b Add support for recording the time to commit in nanoseconds.
834ae5c51b is described below

commit 834ae5c51bf2e82993d5bb48500db38fd3c41660
Author: Mark Thomas <[email protected]>
AuthorDate: Tue Sep 23 08:48:28 2025 +0100

    Add support for recording the time to commit in nanoseconds.
---
 java/org/apache/coyote/Response.java | 18 ++++++++++++++----
 1 file changed, 14 insertions(+), 4 deletions(-)

diff --git a/java/org/apache/coyote/Response.java 
b/java/org/apache/coyote/Response.java
index 283de48272..dc35351dfc 100644
--- a/java/org/apache/coyote/Response.java
+++ b/java/org/apache/coyote/Response.java
@@ -23,6 +23,7 @@ import java.nio.ByteBuffer;
 import java.nio.charset.Charset;
 import java.util.Locale;
 import java.util.Map;
+import java.util.concurrent.TimeUnit;
 import java.util.concurrent.atomic.AtomicBoolean;
 import java.util.concurrent.atomic.AtomicInteger;
 import java.util.function.Supplier;
@@ -122,7 +123,7 @@ public final class Response {
 
     // General information
     private long contentWritten = 0;
-    private long commitTime = -1;
+    private long commitTimeNanos = -1;
 
     /**
      * Holds response writing error exception.
@@ -256,7 +257,7 @@ public final class Response {
 
     public void setCommitted(boolean v) {
         if (v && !this.committed) {
-            this.commitTime = System.currentTimeMillis();
+            this.commitTimeNanos = System.nanoTime();
         }
         this.committed = v;
     }
@@ -267,7 +268,16 @@ public final class Response {
      * @return the time the response was committed
      */
     public long getCommitTime() {
-        return commitTime;
+        return System.currentTimeMillis() - 
TimeUnit.NANOSECONDS.toMillis(System.nanoTime() - commitTimeNanos);
+    }
+
+    /**
+     * Return the time the response was committed (based on System.nanoTime).
+     *
+     * @return the time the response was committed
+     */
+    public long getCommitTimeNanos() {
+        return commitTimeNanos;
     }
 
     // -----------------Error State --------------------
@@ -638,7 +648,7 @@ public final class Response {
         status = 200;
         message = null;
         committed = false;
-        commitTime = -1;
+        commitTimeNanos = -1;
         errorException = null;
         resetError();
         headers.recycle();


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to