You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tomee.apache.org by jl...@apache.org on 2022/12/14 09:46:40 UTC

[tomee] branch main updated: TOMEE-4124 Remove timings of timings for the sake of logging. Another interceptor can be added to drill down if necessary. Make the map thread safe

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

jlmonteiro pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/tomee.git


The following commit(s) were added to refs/heads/main by this push:
     new f9f7d173b1 TOMEE-4124 Remove timings of timings for the sake of logging. Another interceptor can be added to drill down if necessary. Make the map thread safe
f9f7d173b1 is described below

commit f9f7d173b1bf22bfcf5f35fbe972deae6d2de644
Author: Jean-Louis Monteiro <jl...@tomitribe.com>
AuthorDate: Wed Dec 14 10:46:30 2022 +0100

    TOMEE-4124 Remove timings of timings for the sake of logging. Another interceptor can be added to drill down if necessary.
    Make the map thread safe
---
 .../openejb/monitoring/StatsInterceptor.java       | 22 +++-------------------
 1 file changed, 3 insertions(+), 19 deletions(-)

diff --git a/container/openejb-core/src/main/java/org/apache/openejb/monitoring/StatsInterceptor.java b/container/openejb-core/src/main/java/org/apache/openejb/monitoring/StatsInterceptor.java
index ec6654a8c7..509cb56d6c 100644
--- a/container/openejb-core/src/main/java/org/apache/openejb/monitoring/StatsInterceptor.java
+++ b/container/openejb-core/src/main/java/org/apache/openejb/monitoring/StatsInterceptor.java
@@ -39,6 +39,7 @@ import java.lang.reflect.Method;
 import java.util.Collection;
 import java.util.Map;
 import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ConcurrentMap;
 import java.util.concurrent.TimeUnit;
 import java.util.concurrent.atomic.AtomicLong;
 
@@ -54,7 +55,7 @@ public class StatsInterceptor {
 
     public static final InterceptorData metadata = InterceptorData.scan(StatsInterceptor.class);
 
-    private final Map<Method, Stats> map = new ConcurrentHashMap<>();
+    private final ConcurrentMap<Method, Stats> map = new ConcurrentHashMap<>();
     private final AtomicLong invocations = new AtomicLong();
     private final AtomicLong invocationTime = new AtomicLong();
 
@@ -108,11 +109,7 @@ public class StatsInterceptor {
 
     @PostConstruct
     public void PostConstruct(final InvocationContext invocationContext) throws Exception {
-        final long start = System.nanoTime();
         record(invocationContext, PostConstruct());
-        final long end = System.nanoTime();
-        Logger.getInstance(LogCategory.MONITORING, "org.apache.openejb.monitoring")
-                .debug("instance.created", invocationContext.getTarget().getClass().getName(), end - start);
     }
 
     public Method PreDestroy() throws NoSuchMethodException {
@@ -121,11 +118,7 @@ public class StatsInterceptor {
 
     @PreDestroy
     public void PreDestroy(final InvocationContext invocationContext) throws Exception {
-        final long start = System.nanoTime();
         record(invocationContext, PreDestroy());
-        final long end = System.nanoTime();
-        Logger.getInstance(LogCategory.MONITORING, "org.apache.openejb.monitoring")
-                .debug("instance.discarded", invocationContext.getTarget().getClass().getName(), end - start);
     }
 
     public Method PostActivate() throws NoSuchMethodException {
@@ -206,16 +199,7 @@ public class StatsInterceptor {
     private Stats stats(final InvocationContext invocationContext, final Method callback) {
         final Method method = callback == null ? invocationContext.getMethod() : callback;
 
-        Stats stats = map.get(method);
-        if (stats == null) {
-            synchronized (map) {
-                stats = map.get(method);
-                if (stats == null) {
-                    stats = new Stats(method, monitor);
-                    map.put(method, stats);
-                }
-            }
-        }
+        final Stats stats = map.computeIfAbsent(method, m -> new Stats(m, monitor));
         return stats;
     }