The difference between system. Nanotime() and system. Currenttimemillis()


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

  1. System. Currenttimemillis() represents the system time (UTC). System. Nanotime() cannot represent the current time. In essence, it is a random number
  2. System. Currenttimemillis is the same and system. Nanotime () is different on different JVMs on the same machine
  3. 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

[record of pit filling] an instance record of pit filling system. Currenttimemills() with system. Nanotime()

In this paper, the blog group issued a multi article and other operational tools platformOpenWriterelease

Recommended Today

Large scale distributed storage system: Principle Analysis and architecture practice.pdf

Focus on “Java back end technology stack” Reply to “interview” for full interview information Distributed storage system, which stores data in multiple independent devices. Traditional network storage system uses centralized storage server to store all data. Storage server becomes the bottleneck of system performance and the focus of reliability and security, which can not meet […]