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

ahuber pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/isis.git

commit b7303365e0be25744017ff04728c9b8cb392e174
Author: Andi Huber <ahu...@apache.org>
AuthorDate: Fri Aug 31 10:57:34 2018 +0200

    ISIS-1841: improve ThreadPoolSupport's time-resolution for logging
    
    also extend Internal API to support time measuring idioms
---
 .../apache/isis/commons/internal/base/_Timing.java | 85 ++++++++++++++++++++++
 .../core/runtime/threadpool/ThreadPoolSupport.java | 10 +--
 2 files changed, 90 insertions(+), 5 deletions(-)

diff --git 
a/core/commons/src/main/java/org/apache/isis/commons/internal/base/_Timing.java 
b/core/commons/src/main/java/org/apache/isis/commons/internal/base/_Timing.java
new file mode 100644
index 0000000..e34f107
--- /dev/null
+++ 
b/core/commons/src/main/java/org/apache/isis/commons/internal/base/_Timing.java
@@ -0,0 +1,85 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *        http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ */
+
+package org.apache.isis.commons.internal.base;
+
+/**
+ * <h1>- internal use only -</h1>
+ * <p>
+ * Time measuring utilities.
+ * </p>
+ * <p>
+ * <b>WARNING</b>: Do <b>NOT</b> use any of the classes provided by this 
package! <br/>
+ * These may be changed or removed without notice!
+ * </p>
+ *
+ * @since 2.0.0
+ */
+public final class _Timing {
+
+    private _Timing(){}
+
+    /**
+     * @return a new 'now' started instance of {@link StopWatch}
+     */
+    public static StopWatch now() {
+        return new StopWatch();
+    }
+
+    /**
+     * Non thread safe start/stop watch utilizing the currently running
+     * JVM's high-resolution time source.
+     */
+    public static final class StopWatch {
+        
+        private long t0 = 0;
+        private long t1 = 0;
+        private boolean stopped;
+        
+        private StopWatch() {
+            start();
+        }
+        
+        public StopWatch start() {
+            t0 = System.nanoTime();
+            stopped = false;
+            return this;
+        }
+        
+        public StopWatch stop() {
+            t1 = System.nanoTime();
+            stopped  = true;
+            return this;
+        }
+        
+        public double getMillis() {
+            return 0.000_001 * getNanos();
+        }
+        
+        public double getMicros() {
+            return 0.001 * getNanos();
+        }
+        
+        public long getNanos() {
+            return stopped ? t1 - t0 : System.nanoTime() - t0 ;
+        }
+        
+    }
+
+}
diff --git 
a/core/metamodel/src/main/java/org/apache/isis/core/runtime/threadpool/ThreadPoolSupport.java
 
b/core/metamodel/src/main/java/org/apache/isis/core/runtime/threadpool/ThreadPoolSupport.java
index 8295e55..13f220a 100644
--- 
a/core/metamodel/src/main/java/org/apache/isis/core/runtime/threadpool/ThreadPoolSupport.java
+++ 
b/core/metamodel/src/main/java/org/apache/isis/core/runtime/threadpool/ThreadPoolSupport.java
@@ -130,12 +130,12 @@ public final class ThreadPoolSupport implements 
AutoCloseable {
      * @param futures
      * @return list of computation results.
      */
-    public static List<Object> join(final List<Future<Object>> futures) {
+    public static List<Object> join(@Nullable final List<Future<Object>> 
futures) {
         if (futures == null) {
             return null;
         }
-
-        final long t0 = System.currentTimeMillis();
+        
+        final long t0 = System.nanoTime();
         try{
             final List<Object> returnValues = _Lists.newArrayList();
             for (Future<Object> future : futures) {
@@ -143,8 +143,8 @@ public final class ThreadPoolSupport implements 
AutoCloseable {
             }
             return returnValues;
         } finally {
-            final long t1 = System.currentTimeMillis();
-            LOG.info("join'ing {} tasks: waited {} milliseconds ", 
futures.size(), (t1-t0));
+            final long t1 = System.nanoTime();
+            LOG.info("join'ing {} tasks: waited {} milliseconds ", 
futures.size(), 0.000_001 * (t1-t0));
         }
     }
 

Reply via email to