FileDocCategorySizeDatePackage
Counters.javaAPI DocExample1027Wed Apr 20 15:18:14 BST 2005None

Counters

public class Counters extends Object

Fields Summary
int
count1
AtomicInteger
count2
AtomicInteger
count3
Constructors Summary
Methods Summary
public synchronized intcount1()

         return count1++; 
public intcount2()

        return count2.getAndIncrement(); 
public intcount3()

       
        // Get the counter value with get() and set it with compareAndSet().
        // If compareAndSet() returns false, try again until we get 
        // through the loop without interference.
        int result;
        do { 
            result = count3.get();
        } while(!count3.compareAndSet(result, result+1));
        return result;