001 package org.shiftone.jrat.util; 002 003 004 import org.shiftone.jrat.util.log.Logger; 005 006 007 /** 008 * Before there was java.util.concurrent.atomic.AtomicLong, there was 009 * org.shiftone.jrat.util.Sequence. This class was since renamed to make it 010 * obvious what it does. This class does synchronize, while AtomicLong uses a 011 * magic native method. This class supports Java 1.4. 012 * 013 * @author jeff@shiftone.org (Jeff Drost) 014 */ 015 public class AtomicLong { 016 017 private static final Logger LOG = Logger.getLogger(AtomicLong.class); 018 private long value; 019 020 public AtomicLong() { 021 value = 0; 022 } 023 024 025 public AtomicLong(long initialValue) { 026 value = initialValue; 027 } 028 029 030 public synchronized long get() { 031 return value; 032 } 033 034 035 public long incrementAndGet() { 036 return addAndGet(1); 037 } 038 039 040 public synchronized long addAndGet(long delta) { 041 042 value += delta; 043 044 return value; 045 } 046 047 048 public String toString() { 049 return String.valueOf(value); 050 } 051 }