events - millisecond timing in java -
In my Java application, at the beginning of the various transaction transactions of the time, let me start the calendar and then wait for hours, minutes, Getting seconds, and milliseconds gives start time. I complete the transaction, start a new calendar and receive a new hour, minute, seconds and milliseconds. My argument is that the difference between start time and end time is the time of transaction. It works most of the time, but a small fraction of time, the end time is before the start time. Why does this happen and how can I stop it?
Well, one simple way of computing for one thing is the difference System.currentTimeMillis () < / Code> or
System.nanoTime ()
- This way you do not need to do anything other than just a simple subtraction, number of milliseconds between initial and end or To get the number of nanoseconds
However, if your system clock is being updated with NTP or something similar, then the timing can sometimes go backwards - how the clock is handled diagonally. (Some systems slow down the system clock for a while so that it can be returned to reality, others may have dissatisfaction.)
I am not the best way to ensure - I do not believe Currently, JR has something equal to stopwatch
which is in NIT, which is completely to measure the gap and (I do not believe) The system clock changes by changing the clock is. / P>
(I think BTW along with Eric's recommendation - although I do not think you need it for this particular problem.)
Comments
Post a Comment