当前位置:网站首页>Solve high and send system Currenttimemillis Caton
Solve high and send system Currenttimemillis Caton
2022-07-03 03:12:00 【Friendship years】
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();
}
/**
* To replace the original System.currentTimeMillis()
*/
public static long now() {
return instance().currentTimeMillis();
}
边栏推荐
- labelme标记的文件转换为yolov5格式
- 【富瀚6630编码存录像,用rtsp服务器及时间戳同步实现vlc观看录像】
- Source code analysis | resource loading resources
- Use of El tree search method
- Agile certification (professional scrum Master) simulation exercises
- How to select the minimum and maximum values of columns in the data table- How to select min and max values of a column in a datatable?
- 左连接,内连接
- 二维数组中的元素求其存储地址
- Deep reinforcement learning for intelligent transportation systems: a survey paper reading notes
- The difference between componentscan and componentscans
猜你喜欢
![MySQL Real combat 45 [SQL query and Update Execution Process]](/img/cd/3a635f0c3bb4ac3c8241cb77285cc8.png)
MySQL Real combat 45 [SQL query and Update Execution Process]

PAT乙级“1104 天长地久”DFS优化思路

MySql实战45讲【行锁】

el-tree搜索方法使用

Kubernetes family container housekeeper pod online Q & A?

内存泄漏工具VLD安装及使用

函数栈帧的创建与销毁
![[pyg] understand the messagepassing process, GCN demo details](/img/8b/8490aac98fd2753e661f74e284f43d.png)
[pyg] understand the messagepassing process, GCN demo details

Practice of traffic recording and playback in vivo
![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
随机推荐
3D drawing example
Introduction to cron expression
解决高并发下System.currentTimeMillis卡顿
Segmentation fault occurs during VFORK execution
Andwhere multiple or query ORM conditions in yii2
力扣------网格中的最小路径代价
File rename
迅雷chrome扩展插件造成服务器返回的数据js解析页面数据异常
基于Qt的yolov5工程
Cron表达式介绍
How to use asp Net MVC identity 2 change password authentication- How To Change Password Validation in ASP. Net MVC Identity 2?
Idea set method call ignore case
Do you really understand relays?
I2C subsystem (III): I2C driver
Joking about Domain Driven Design (III) -- Dilemma
How to return ordered keys after counter counts the quantity
销毁Session和清空指定的属性
ComponentScan和ComponentScans的区别
模型转换onnx2engine
Privatization lightweight continuous integration deployment scheme -- 01 environment configuration (Part 2)