void requestExecution ( ) { for ( ; ; ) { State currentState = state . get ( ) ; switch ( currentState ) { case INACTIVE : if ( state . compareAndSet ( State . INACTIVE , State . RUNNING ) ) { scheduleExecution ( ) ; return ; } break ; case RUNNING : if ( state . compareAndSet ( State . RUNNING , State . REQUESTED ) ) { return ; } break ; default : //someone else already requested execution return ; } } }
Request a new task execution if needed .