The initial value of system. Nanotime() is inThis JVM instanceA number selected “randomly” at startup changes with the operation of the JVM. System. Currenttimemillis represents the system time, which leads to several differences between them
- System. Currenttimemillis() represents the system time (UTC). System. Nanotime() cannot represent the current time. In essence, it is a random number
- System. Currenttimemillis is the same and system. Nanotime () is different on different JVMs on the same machine
- System.currentTimeMillis () system is time sensitive, System.nanoTime () system is not sensitive to time. For example, we will forward the system time one second, System.currentTimeMillis () will be reduced by 1000. compared with before, and System.nanoTime () will not change.
Based on the time insensitive property of system. Nanotime (), it is widely used in scenarios that require relative time, such as scheduledthreadpool executor, adding a task to be executed after 1 hour at 0:00, then it will not be triggered until 1 hour after the system runs, no matter how the system time is modified during this period
In this paper, the blog group issued a multi article and other operational tools platformOpenWriterelease