当前位置:网站首页>解决高并发下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();
}
边栏推荐
- The difference between left value and right value in C language
- Agile certification (professional scrum Master) simulation exercise-2
- I2C 子系统(一):I2C spec
- VS 2019配置tensorRT
- I2C 子系统(三):I2C Driver
- VS 2019安装及配置opencv
- 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)
- Do you really understand relays?
- Nasvit: neural architecture search of efficient visual converter with gradient conflict perception hypernetwork training
- Unity3d human skin real time rendering real simulated human skin real time rendering "suggestions collection"
猜你喜欢
随机推荐
[Fuhan 6630 encodes and stores videos, and uses RTSP server and timestamp synchronization to realize VLC viewing videos]
MySql实战45讲【全局锁和表锁】
Anhui University | small target tracking: large-scale data sets and baselines
The idea setting code is in UTF-8 idea Properties configuration file Chinese garbled
Kubernetes family container housekeeper pod online Q & A?
Docker install MySQL
PHP constructor with parameters - PHP constructor with a parameter
Sous - système I2C (IV): débogage I2C
Reset or clear NET MemoryStream - Reset or Clear . NET MemoryStream
MySQL practice 45 [global lock and table lock]
Practice of traffic recording and playback in vivo
Andwhere multiple or query ORM conditions in yii2
The difference between left value and right value in C language
labelme标记的文件转换为yolov5格式
I2C 子系统(一):I2C spec
The difference between componentscan and componentscans
I2C subsystem (II): I3C spec
45 lectures on MySQL [index]
I2C subsystem (I): I2C spec
docker安装mysql









