synchronized int checkState ( ) { if ( this . state == Job . RUNNING ) { checkRunningState ( ) ; } if ( this . state != Job . WAITING ) { return this . state ; } if ( this . dependingJobs == null || this . dependingJobs . size ( ) == 0 ) { this . state = Job . READY ; return this . state ; } Job pred = null ; int n = this . dependingJobs . size ( ) ; for ( int i = 0 ; i < n ; i ++ ) { pred = this . dependingJobs . get ( i ) ; int s = pred . checkState ( ) ; if ( s == Job . WAITING || s == Job . READY || s == Job . RUNNING ) { break ; // a pred is still not completed, continue in WAITING // state } if ( s == Job . FAILED || s == Job . DEPENDENT_FAILED ) { this . state = Job . DEPENDENT_FAILED ; this . message = "depending job " + i + " with jobID " + pred . getJobID ( ) + " failed. " + pred . getMessage ( ) ; break ; } // pred must be in success state if ( i == n - 1 ) { this . state = Job . READY ; } } return this . state ; }
Check and update the state of this job . The state changes depending on its current state and the states of the depending jobs .