public String nextId ( ) { String id = "-1" ; do { // when we reach max int, reset to zero if ( nextId . get ( ) == Integer . MAX_VALUE ) { nextId . set ( 0 ) ; } id = String . format ( "%d" , nextId . getAndIncrement ( ) ) ; } while ( hasClient ( id ) ) ; return id ; }
Return next client id