private boolean tryIncrement(AtomicInteger counter,int max){
  while (true) {
    int count=counter.get();
    if (count >= max && max != 0)     return false;
    if (counter.compareAndSet(count,count + 1))     return true;
  }
}

private boolean tryIncrement ( AtomicInteger counter , int max ) { while ( true ) { int count = counter . get ( ) ; if ( count >= max && max != 0 ) return false ; if ( counter . compareAndSet ( count , count + 1 ) ) return true ; } }
attempts to increment the given atomicinteger without exceeding the specified maximum value . if the atomicinteger cannot be incremented without exceeding the maximum , false is returned .
