private int incrementAndGet(AtomicInteger value,int max){
  while (true) {
    int cur=value.get();
    int next=cur == max ? 0 : cur + 1;
    if (value.compareAndSet(cur,next))     return next;
  }
}

private int incrementAndGet ( AtomicInteger value , int max ) { while ( true ) { int cur = value . get ( ) ; int next = cur == max ? 0 : cur + 1 ; if ( value . compareAndSet ( cur , next ) ) return next ; } }
atomically increments the given value by one , re - starting from 0 when the specified maximum is reached .
