当前位置:网站首页>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();
}
边栏推荐
- 将时间戳转为指定格式的时间
- The difference between componentscan and componentscans
- Edit and preview in the back pipe to get the value writing method of the form
- Update and return document in mongodb - update and return document in mongodb
- 为什么线程崩溃不会导致 JVM 崩溃
- Are there any recommended term life insurance products? I want to buy a term life insurance.
- VS 2019安装及配置opencv
- Use cve-2021-43893 to delete files on the domain controller
- ComponentScan和ComponentScans的区别
- Installation and use of memory leak tool VLD
猜你喜欢

Spark on yarn resource optimization ideas notes

I2C 子系统(三):I2C Driver

From C to capable -- use the pointer as a function parameter to find out whether the string is a palindrome character

docker安装redis

Segmentation fault occurs during VFORK execution

C language beginner level - pointer explanation - paoding jieniu chapter
![45 lectures on MySQL [index]](/img/f6/70be00028908cbd9ed7f2c77687cee.png)
45 lectures on MySQL [index]

Le processus de connexion mysql avec docker

Three. JS local environment setup

Vs Code configure virtual environment
随机推荐
你真的懂继电器吗?
为什么线程崩溃不会导致 JVM 崩溃
VS 2019配置tensorRT
I2C subsystem (III): I2C driver
idea 加载不了应用市场解决办法(亲测)
Le processus de connexion mysql avec docker
文件重命名
Are there any recommended term life insurance products? I want to buy a term life insurance.
PHP constructor with parameters - PHP constructor with a parameter
Distributed transaction
Use optimization | points that can be optimized in recyclerview
[C语言]给账号密码进行MD5加密
PAT乙级“1104 天长地久”DFS优化思路
[Chongqing Guangdong education] cultural and natural heritage reference materials of China University of Geosciences (Wuhan)
解决高并发下System.currentTimeMillis卡顿
What happens between entering the URL and displaying the page?
com.fasterxml.jackson.databind.exc.InvalidFormatException问题
Can netstat still play like this?
别再用 System.currentTimeMillis() 统计耗时了,太 Low,StopWatch 好用到爆!
C language beginner level - pointer explanation - paoding jieniu chapter