当前位置:网站首页>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();
}
边栏推荐
- 内存泄漏工具VLD安装及使用
- 函数栈帧的创建与销毁
- Deep reinforcement learning for intelligent transportation systems: a survey paper reading notes
- How do you adjust the scope of activerecord Association in rails 3- How do you scope ActiveRecord associations in Rails 3?
- Can netstat still play like this?
- Practice of traffic recording and playback in vivo
- MySQL practice 45 [SQL query and update execution process]
- @Accessors注解作用指定前缀遵守驼峰命名
- Add automatic model generation function to hade
- 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
猜你喜欢

MySql实战45讲【事务隔离】

VS 2019 配置tensorRT生成engine

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

Creation and destruction of function stack frame

The idea cannot be loaded, and the market solution can be applied (pro test)

vfork执行时出现Segmentation fault

Docker install MySQL

Distributed transaction

el-tree搜索方法使用

左连接,内连接
随机推荐
模型转换onnx2engine
MySQL practice 45 [SQL query and update execution process]
[C language] MD5 encryption for account password
From C to capable -- use the pointer as a function parameter to find out whether the string is a palindrome character
[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
一文带你了解 ZigBee
[shutter] monitor the transparency gradient of the scrolling action control component (remove the blank of the top status bar | frame layout component | transparency component | monitor the scrolling
Check log4j problems using stain analysis
What does it mean when lambda is not entered?
MySQL practice 45 lecture [transaction isolation]
Kubernetes family container housekeeper pod online Q & A?
文件重命名
解决高并发下System.currentTimeMillis卡顿
File rename
Do you really understand relays?
How to return ordered keys after counter counts the quantity
程序员新人上午使用 isXxx 形式定义布尔类型,下午就被劝退?
vfork执行时出现Segmentation fault
VS 2019 配置tensorRT生成engine
I2C subsystem (III): I2C driver