AtomicLong operations
问题 I need to perform the following operation: // average, total, elapsed are Long's average = ( ( total * average ) + elapsed ) / (++total); But I want to use AtomicLong This is what I'm trying but I don't quite get if it is correct: average.set( (( total.get() * average.get() ) + elapsed) / total.getAndIncrement() ); How can I tell if this is correct? 回答1: Presumably you are using AtomicLong because these numbers are being accessed concurrently. Since you have two numbers involved and you are