当前位置:网站首页>解决高并发下System.currentTimeMillis卡顿
解决高并发下System.currentTimeMillis卡顿
2022-07-03 03:08:00 【&友情岁月&】
public class SystemClock { private final int period; private final AtomicLong now; private static class InstanceHolder { private static final SystemClock INSTANCE = new SystemClock(1); } private SystemClock(int period) { this.period = period; this.now = new AtomicLong(System.currentTimeMillis()); scheduleClockUpdating(); } private static SystemClock instance() { return InstanceHolder.INSTANCE; } private void scheduleClockUpdating() { ScheduledExecutorService scheduler = Executors.newSingleThreadScheduledExecutor(runnable -> { Thread thread = new Thread(runnable, "System Clock"); thread.setDaemon(true); return thread; }); scheduler.scheduleAtFixedRate(() -> now.set(System.currentTimeMillis()), period, period, TimeUnit.MILLISECONDS); } private long currentTimeMillis() { return now.get(); } /** * 用来替换原来的System.currentTimeMillis() */ public static long now() { return instance().currentTimeMillis(); }
边栏推荐
- Cron表达式介绍
- I2C 子系统(四):I2C debug
- [combinatorics] Application of exponential generating function (multiple set arrangement problem | different balls in different boxes | derivation of exponential generating function of odd / even sequ
- VS 2019配置tensorRT
- The difference between componentscan and componentscans
- As a leader, how to control the code version and demand development when the epidemic comes| Community essay solicitation
- 基于Qt的yolov5工程
- Deep learning: multi-layer perceptron and XOR problem (pytoch Implementation)
- MySQL practice 45 lecture [row lock]
- Force deduction ----- the minimum path cost in the grid
猜你喜欢
你真的懂继电器吗?
[principles of multithreading and high concurrency: 1_cpu multi-level cache model]
Creation and destruction of function stack frame
MySql实战45讲【行锁】
力扣------网格中的最小路径代价
Vs 2019 configuration du moteur de génération de tensorrt
MySQL Real combat 45 [SQL query and Update Execution Process]
Kubernetes cluster log and efk architecture log scheme
Gavin teacher's perception of transformer live class - rasa project's actual banking financial BOT Intelligent Business Dialogue robot architecture, process and phenomenon decryption through rasa inte
TCP 三次握手和四次挥手机制,TCP为什么要三次握手和四次挥手,TCP 连接建立失败处理机制
随机推荐
左连接,内连接
Deep reinforcement learning for intelligent transportation systems: a survey paper reading notes
JS finds all the parent nodes or child nodes under a node according to the tree structure
L'index des paramètres d'erreur est sorti de la plage pour les requêtes floues (1 > Nombre de paramètres, qui est 0)
VS 2019安装及配置opencv
I2C subsystem (II): I3C spec
Kubernetes cluster log and efk architecture log scheme
敏捷认证(Professional Scrum Master)模拟练习题
Distributed transaction
VS code配置虚拟环境
How to use asp Net MVC identity 2 change password authentication- How To Change Password Validation in ASP. Net MVC Identity 2?
用docker 连接mysql的过程
函数栈帧的创建与销毁
docker安装mysql
Didi programmers are despised by relatives: an annual salary of 800000 is not as good as two teachers
MySql实战45讲【SQL查询和更新执行流程】
idea 加载不了应用市场解决办法(亲测)
Use optimization | points that can be optimized in recyclerview
Kubernetes family container housekeeper pod online Q & A?
MySQL Real combat 45 [SQL query and Update Execution Process]