Code example for AtomicInteger

Methods: getAndDecrementincrementAndGet

0
     * Decrements by one the current value and Returns the previous value 
     * 
     * @return the previous value 
     */ 
    public int getAndDecrement() { 
        int ret = this.counter.getAndDecrement();
        if (ret <= 0) {
            this.counter.incrementAndGet();
            return 0; 
        } else { 
            return ret;
        } 
    } 
 
    /** 
     * Increments by one the current value and Returns the the updated value 
     * 
     * @return the updated value 
     */ 
    public int incrementAndGet() { 
Stop searching for code, let great code find you!  Add Codota to your java IDE