Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id 8B13A200CF0 for ; Thu, 7 Sep 2017 08:35:13 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id 898BA161CDC; Thu, 7 Sep 2017 06:35:13 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id D314F161CAD for ; Thu, 7 Sep 2017 08:35:12 +0200 (CEST) Received: (qmail 95354 invoked by uid 500); 7 Sep 2017 06:35:11 -0000 Mailing-List: contact dev-help@activemq.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@activemq.apache.org Delivered-To: mailing list dev@activemq.apache.org Received: (qmail 95343 invoked by uid 99); 7 Sep 2017 06:35:11 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 07 Sep 2017 06:35:11 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 0FAF1F553D; Thu, 7 Sep 2017 06:35:11 +0000 (UTC) From: michaelandrepearce To: dev@activemq.apache.org Reply-To: dev@activemq.apache.org References: In-Reply-To: Subject: [GitHub] activemq-artemis pull request #1515: ARTEMIS-1393 CriticalAnalyzer timeout u... Content-Type: text/plain Message-Id: <20170907063511.0FAF1F553D@git1-us-west.apache.org> Date: Thu, 7 Sep 2017 06:35:11 +0000 (UTC) archived-at: Thu, 07 Sep 2017 06:35:13 -0000 Github user michaelandrepearce commented on a diff in the pull request: https://github.com/apache/activemq-artemis/pull/1515#discussion_r137456099 --- Diff: artemis-commons/src/main/java/org/apache/activemq/artemis/utils/critical/CriticalMeasure.java --- @@ -17,28 +17,39 @@ package org.apache.activemq.artemis.utils.critical; -import org.jboss.logging.Logger; +import java.util.concurrent.TimeUnit; +import java.util.concurrent.atomic.AtomicLongFieldUpdater; -public class CriticalMeasure { +final class CriticalMeasure { - private static final Logger logger = Logger.getLogger(CriticalMeasure.class); + //uses updaters to avoid creates many AtomicLong instances + private static final AtomicLongFieldUpdater TIME_ENTER_UPDATER = AtomicLongFieldUpdater.newUpdater(CriticalMeasure.class, "timeEnter"); + private static final AtomicLongFieldUpdater TIME_LEFT_UPDATER = AtomicLongFieldUpdater.newUpdater(CriticalMeasure.class, "timeLeft"); - private volatile long timeEnter; - private volatile long timeLeft; + //System::nanoTime can't reach this value so it's the best candidate to have a NULL semantic + private static final long NIL = Long.MAX_VALUE; + private volatile long timeEnter = NIL; + private volatile long timeLeft = NIL; public void enterCritical() { - timeEnter = System.currentTimeMillis(); + //prefer lazySet in order to avoid heavy-weight full barriers + TIME_ENTER_UPDATER.lazySet(this, System.nanoTime()); } public void leaveCritical() { - timeLeft = System.currentTimeMillis(); + final long now = System.nanoTime(); + assert TIME_ENTER_UPDATER.get(this) <= now : "Must call enterCritical first"; --- End diff -- +1 ---