当前位置:网站首页>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();
}
边栏推荐
- PHP constructor with parameters - PHP constructor with a parameter
- Sqlserver row to column pivot
- 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
- [combinatorics] number of solutions of indefinite equations (number of combinations of multiple sets R | number of non negative integer solutions of indefinite equations | number of integer solutions
- 【富瀚6630编码存录像,用rtsp服务器及时间戳同步实现vlc观看录像】
- From C to capable -- use the pointer as a function parameter to find out whether the string is a palindrome character
- Thunderbolt Chrome extension caused the data returned by the server JS parsing page data exception
- 销毁Session和清空指定的属性
- Privatization lightweight continuous integration deployment scheme -- 01 environment configuration (Part 2)
- Cron表达式介绍
猜你喜欢

TCP 三次握手和四次挥手机制,TCP为什么要三次握手和四次挥手,TCP 连接建立失败处理机制

VS 2019 配置tensorRT生成engine

Deep learning: multi-layer perceptron and XOR problem (pytoch Implementation)

一文带你了解 ZigBee

分布式事务

Joking about Domain Driven Design (III) -- Dilemma

敏捷认证(Professional Scrum Master)模拟练习题-2

I2C 子系统(四):I2C debug

Idea set method call ignore case

From C to capable -- use the pointer as a function parameter to find out whether the string is a palindrome character
随机推荐
【富瀚6630编码存录像,用rtsp服务器及时间戳同步实现vlc观看录像】
用docker 連接mysql的過程
MySql实战45讲【事务隔离】
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?
docker安装mysql
How do you adjust the scope of activerecord Association in rails 3- How do you scope ActiveRecord associations in Rails 3?
Idea format code idea set shortcut key format code
PAT乙级“1104 天长地久”DFS优化思路
[C language] MD5 encryption for account password
VS 2019安装及配置opencv
Distributed transaction
C # general interface call
File rename
Creation and destruction of function stack frame
为什么线程崩溃不会导致 JVM 崩溃
Installation and use of memory leak tool VLD
MySQL practice 45 lecture [row lock]
Can netstat still play like this?
TCP 三次握手和四次挥手机制,TCP为什么要三次握手和四次挥手,TCP 连接建立失败处理机制
Check log4j problems using stain analysis