From e875596aff0b80d85e63b8fa9815170133d1b68c Mon Sep 17 00:00:00 2001 From: haijun <2778829758@qq.com> Date: Wed, 3 Jul 2024 11:53:32 +0800 Subject: [PATCH] =?UTF-8?q?SystemClock.InstanceHolder=E7=9A=84=E6=88=90?= =?UTF-8?q?=E5=91=98=E5=B1=9E=E6=80=A7now=E6=98=AF=E4=B8=80=E5=86=99?= =?UTF-8?q?=E5=A4=9A=E8=AF=BB=EF=BC=8C=E4=BB=8EAtomicLong=E6=9B=BF?= =?UTF-8?q?=E6=8D=A2=E4=B8=BA=E5=B8=A6volatile=E4=BF=AE=E9=A5=B0=E7=9A=84?= =?UTF-8?q?=E5=9F=BA=E6=9C=AC=E6=95=B0=E6=8D=AE=E7=B1=BB=E5=9E=8B=EF=BC=8C?= =?UTF-8?q?=E9=81=BF=E5=85=8D=E6=97=A0=E6=84=8F=E4=B9=89=E7=9A=84CAS?= =?UTF-8?q?=E6=93=8D=E4=BD=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/jd/platform/async/executor/timer/SystemClock.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/asyncTool-core/src/main/java/com/jd/platform/async/executor/timer/SystemClock.java b/asyncTool-core/src/main/java/com/jd/platform/async/executor/timer/SystemClock.java index 6cba50a..cd578d7 100644 --- a/asyncTool-core/src/main/java/com/jd/platform/async/executor/timer/SystemClock.java +++ b/asyncTool-core/src/main/java/com/jd/platform/async/executor/timer/SystemClock.java @@ -13,7 +13,7 @@ public class SystemClock { private final int period; - private final AtomicLong now; + private volatile long now; private static class InstanceHolder { private static final SystemClock INSTANCE = new SystemClock(1); @@ -21,7 +21,7 @@ public class SystemClock { private SystemClock(int period) { this.period = period; - this.now = new AtomicLong(System.currentTimeMillis()); + this.now = System.currentTimeMillis(); scheduleClockUpdating(); } @@ -35,11 +35,11 @@ public class SystemClock { thread.setDaemon(true); return thread; }); - scheduler.scheduleAtFixedRate(() -> now.set(System.currentTimeMillis()), period, period, TimeUnit.MILLISECONDS); + scheduler.scheduleAtFixedRate(() -> now = System.currentTimeMillis(), period, period, TimeUnit.MILLISECONDS); } private long currentTimeMillis() { - return now.get(); + return now; } /** -- Gitee