private static boolean updateIfSmaller ( AtomicInteger counter , int value ) { for ( ; ; ) { int snapshotCoutner = counter . get ( ) ; if ( snapshotCoutner >= value ) return false ; if ( counter . compareAndSet ( snapshotCoutner , value ) ) return true ; } }
Update the counter to the value provided it is greater . Regardless of the returned value it is guaranteed that the value of the counter after execution will be at least the input value .