Reputation: 756
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?
Upvotes: 7
Views: 1784
Reputation: 98304
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
.
Upvotes: 9