当前位置:网站首页>解决高并发下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();
}
边栏推荐
- Variable declarations following if statements
- [Fuhan 6630 encodes and stores videos, and uses RTSP server and timestamp synchronization to realize VLC viewing videos]
- [Chongqing Guangdong education] cultural and natural heritage reference materials of China University of Geosciences (Wuhan)
- VS 2019 配置tensorRT生成engine
- vfork执行时出现Segmentation fault
- Deep reinforcement learning for intelligent transportation systems: a survey paper reading notes
- C语言初阶-指针详解-庖丁解牛篇
- I2C subsystem (II): I3C spec
- 用docker 连接mysql的过程
- 模糊查詢時報錯Parameter index out of range (1 > number of parameters, which is 0)
猜你喜欢

3D drawing example

Installation and use of memory leak tool VLD

What is the way out for children from poor families?

TCP handshake three times and wave four times. Why does TCP need handshake three times and wave four times? TCP connection establishes a failure processing mechanism
![ASP. Net core 6 framework unveiling example demonstration [02]: application development based on routing, MVC and grpc](/img/cb/145937a27ef08050a370d5a255215a.jpg)
ASP. Net core 6 framework unveiling example demonstration [02]: application development based on routing, MVC and grpc
![MySQL practice 45 lecture [row lock]](/img/71/344daddee537a96f0d38241e6896e1.png)
MySQL practice 45 lecture [row lock]

Distributed transaction

Nasvit: neural architecture search of efficient visual converter with gradient conflict perception hypernetwork training

Agile certification (professional scrum Master) simulation exercise-2

MySql实战45讲【SQL查询和更新执行流程】
随机推荐
Vs 2019 configure tensorrt to generate engine
Update and return document in mongodb - update and return document in mongodb
Kubernetes family container housekeeper pod online Q & A?
Use of El tree search method
[combinatorics] Application of exponential generating function (multiple set arrangement problem | different balls in different boxes | derivation of exponential generating function of odd / even sequ
docker安装mysql
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)
用docker 連接mysql的過程
Source code analysis | layout file loading process
el-tree搜索方法使用
VS 2019配置tensorRT
处理数据集,使用LabelEncoder将所有id转换为从0开始
MySQL practice 45 lecture [transaction isolation]
Process the dataset and use labelencoder to convert all IDs to start from 0
3D drawing example
The process of connecting MySQL with docker
I2C 子系统(一):I2C spec
What does it mean when lambda is not entered?
Spark on yarn resource optimization ideas notes
I2C subsystem (II): I3C spec