Clock & Timer resolution(시간, 타이머 해상도)Clock & Timer resolution(시간, 타이머 해상도)

Posted at 2013. 1. 30. 15:28 | Posted in 개발이야기

출처: https://blogs.oracle.com/dholmes/entry/inside_the_hotspot_vm_clocks


clock에는 다음 2가지가 있다.

  • absolute clock (the time-of-day clock, with a low resolution)
  • relative clock (some kind of "high-resolution" counter from which a "free-running" time can be calculated)


현대 컴퓨터에서는 clock과 timer는 큰 차이가 있다.

The resolution of clocks and timers in modern computers is typically very different.

timed events are triggered by operating system controlled interrupts that are normally much more coarse grained (typically 10ms)

Further, systems often have a quite different resolution for the time-of-day clock (often low resolution of 10ms or worse) and the free-running relative clock (microseconds or better), because they are actually derived from quite different pieces of hardware.


absolute clock(time-of-day)는 자바에서 System.currentTimeMillis()로 구현된다.

(System.currentTimeMillis() = 'time-of-day' clock. update resolution is same as the timer interrupt(eg. 10ms).)

The absolute "time-of-day" clock is represented by the System.currentTimeMillis() method, that returns a millisecond representation of wall-clock time in milliseconds since the epoch. As such it uses the operating system's "time of day" clock. The update resolution of this clock is often the same as the timer interrupt (eg. 10ms), but on some systems is fixed, independent of the interrupt rate.


relative-time clock 은 자바에서 System.nanoTime()으로 구현된다. high-resolution이다.

The relative-time clock is represented by the System.nanoTime() method that returns a "free-running" time in nanoseconds.

The nanoTime method uses the highest resolution clock available on the platform, and while its return value is in nanoseconds, the update resolution is typically only microseconds.

However, on some systems there is no choice but to use the same clock source as for currentTimeMillis() - fortunately this is rare and mostly affects old Linux systems, and Windows 98.


자바 타이머 관련 클래스의 해상도.

  • The java.util.Timer and java.util.TimerTask - use of currentTimeMillis()
  • Java 5.0 ScheduledThreadPoolExecutor (STPE) - use of nanoTime()



//