Class Clock
- java.lang.Object
-
- com.gurock.smartinspect.Clock
-
public class Clock extends Object
Provides access to the current date and time, optionally with a high resolution.See now for a method which returns the current date and time, optionally with a very high resolution. See calibrate for a method which can synchronize the high-resolution timer with the system clock.
This class is fully threadsafe.
- See Also:
ClockResolution
-
-
Constructor Summary
Constructors Constructor Description Clock()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static voidcalibrate()Calibrates the high-resolution timer and synchronizes it with the system clock.static longnow(ClockResolution resolution)Returns the current date and time, optionally with a high resolution.
-
-
-
Method Detail
-
now
public static long now(ClockResolution resolution)
Returns the current date and time, optionally with a high resolution.If ClockResolution.High is passed as value for the resolution argument, this method tries to return a timestamp with a microsecond resolution.
The SmartInspect Java library needs an external DLL to be able to use high-resolution timestamps. This DLL is called SmartInspect.Java.dll. If this DLL cannot be found during application startup, high-resolution support is not available. Additionally, even if this DLL is found and loaded correctly, high-resolution timestamps are only available if the QueryPerformanceCounter and QueryPerformanceFrequency Windows functions indicate a successfully working high-resolution performance counter.
Please note that high-resolution timestamps are not intended to be used on production systems. It is recommended to use them only during development and debugging. See SmartInspect.setResolution for details.
If high-resolution support is not available, this method simply returns the local date and time with the help of the System.currentTimeMillis() function and the default time zone.
- Parameters:
resolution- Specifies the desired resolution mode for the returned timestamp- Returns:
- The current local date and time in microseconds since January 1, 1970
-
calibrate
public static void calibrate()
Calibrates the high-resolution timer and synchronizes it with the system clock.Use this method to calibrate the high-resolution timer and to improve the timer synchronization with the system clock.
Background: Without calling this method before calling now in high-resolution mode, now returns a value which is only loosely synchronized with the system clock. The returned value might differ by a few milliseconds. This can usually safely be ignored for a single process application, but may be an issue for distributed interacting applications with multiple processes. In this case, calling calibrate once on application startup might be necessary to improve the system clock synchronization of each process in order to get comparable timestamps across all processes.
Note that calling this method is quite costly, it can easily take 50 milliseconds, depending on the system clock timer resolution of the underlying operating system. Also note that the general limitations (see SmartInspect.setResolution) of high-resolution timestamps still apply after calling this method.
-
-