当前位置:网站首页>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(); }
边栏推荐
- File rename
- MySQL practice 45 [global lock and table lock]
- [pyg] understand the messagepassing process, GCN demo details
- Force freeing memory in PHP
- Vs Code configure virtual environment
- Update and return document in mongodb - update and return document in mongodb
- MySql實戰45講【SQL查詢和更新執行流程】
- [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
- Three. JS local environment setup
- Basic information of Promethus (I)
猜你喜欢
[principles of multithreading and high concurrency: 1_cpu multi-level cache model]
Anhui University | small target tracking: large-scale data sets and baselines
VS 2019安装及配置opencv
Idea set method call ignore case
左连接,内连接
内存泄漏工具VLD安装及使用
MySQL practice 45 [SQL query and update execution process]
为什么线程崩溃不会导致 JVM 崩溃
el-tree搜索方法使用
Distributed transaction
随机推荐
JS finds all the parent nodes or child nodes under a node according to the tree structure
com.fasterxml.jackson.databind.exc.InvalidFormatException问题
Practice of traffic recording and playback in vivo
[C language] MD5 encryption for account password
Distributed transaction
Model transformation onnx2engine
Do you really understand relays?
Getting started | jetpack hilt dependency injection framework
I2C 子系统(四):I2C debug
Can netstat still play like this?
MySql实战45讲【事务隔离】
Update and return document in mongodb - update and return document in mongodb
labelimg生成的xml文件转换为voc格式
Last update time of all sqlserver tables
The idea cannot be loaded, and the market solution can be applied (pro test)
解决高并发下System.currentTimeMillis卡顿
【PyG】理解MessagePassing过程,GCN demo详解
Variable declarations following if statements
Change cell color in Excel using C - cell color changing in Excel using C
How do you adjust the scope of activerecord Association in rails 3- How do you scope ActiveRecord associations in Rails 3?