Is the method System.currentTimeMillis()
implemented to make a system call to the underlying operating system in order to receive the current time?
I ask since as far as I know, the method runs pretty fast, and takes as little as 6 CPU clocks, but this doesn't make sense because system calls are known to be slow.
What am I missing here?
System.currentTimeMillis()
does not usually require switching to kernel mode. OS provides a mechanism that allows reading current time from user mode by mapping corresponding kernel pages directly into application address space.
E.g. Oracle JDK and OpenJDK implementation of System.currentTimeMillis()
on Linux calls glibc gettimeofday
function. This call accesses kernel data directly from user space by means of vDSO
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With