boolean detectLongRunningJob ( long currentTime , Job job ) { if ( job . status ( ) == JobStatus . RUNNING && ! longRunningJobs . containsKey ( job ) ) { int jobExecutionsCount = job . executionsCount ( ) ; Long jobStartedtimeInMillis = job . lastExecutionStartedTimeInMillis ( ) ; Thread threadRunningJob = job . threadRunningJob ( ) ; if ( jobStartedtimeInMillis != null && threadRunningJob != null && currentTime - jobStartedtimeInMillis > detectionThresholdInMillis ) { logger . warn ( "Job '{}' is still running after {}ms (detection threshold = {}ms), stack trace = {}" , job . name ( ) , currentTime - jobStartedtimeInMillis , detectionThresholdInMillis , Stream . of ( threadRunningJob . getStackTrace ( ) ) . map ( StackTraceElement :: toString ) . collect ( Collectors . joining ( "\n " ) ) ) ; longRunningJobs . put ( job , new LongRunningJobInfo ( jobStartedtimeInMillis , jobExecutionsCount ) ) ; return true ; } } return false ; }
Check whether a job is running for too long or not .