[concurrency-interest] Re: SynchronizedLong vs. other locks

Tim Peierls tim at peierls.net
Fri Jul 8 12:20:48 EDT 2005


Aleksey Gureev wrote:
> ...if you write an application and you need some timestamp to mark the
> event time or something -- currentTimeMillis() is your best friend. Just
> don't make a mistake thinking about it as a precise date and you'll find
> tons of other applications. :)

It wasn't clear from your code fragment whether you were concerned about 
having a precise date. You might have thought (as I did until now) that 
GregorianCalendar works with corrected UTC time, in which case date 
computations using currentTimeMillis would not agree with GregorianCalendar 
date computations.

Seems like an appropriate time to remind folks that System.nanoTime (unlike 
System.currentTimeMillis) is *only* good for measuring elapsed time, never 
wall-clock time. This is pretty clearly spelled out in the javadocs, but it 
can't hurt to repeat it.

--tim



More information about the Concurrency-interest mailing list