public void run ( ) { if ( TraceComponent . isAnyTracingEnabled ( ) && tc . isEntryEnabled ( ) ) SibTr . entry ( tc , "run" ) ; try { //loop until finished while ( ! finished ) { //what time is it now long now = System . currentTimeMillis ( ) ; boolean fire = false ; //synchronize on the wake up lock synchronized ( wakeupLock ) { //if not suspended and we've reached or passed the target wakeup time if ( running ) { fire = ( now >= nextWakeup ) ; } } if ( fire ) { //call the internal alarm method which should return the //time for the next wakeup ... or SUSPEND if the thread should be suspended manager . fireInternalAlarm ( ) ; synchronized ( wakeupLock ) { setNextWakeup ( manager . getNextWakeup ( ) ) ; } } synchronized ( wakeupLock ) { //if we are still not suspended (another thread could have got in before // the re-lock and changed things) if ( running ) { //if there is still time until the next wakeup if ( wakeupDelta > 0 ) { try { if ( ! finished ) { if ( TraceComponent . isAnyTracingEnabled ( ) && tc . isDebugEnabled ( ) ) SibTr . debug ( tc , "Thread wait : " + wakeupDelta ) ; //wait until the next target wakeup time long start = System . currentTimeMillis ( ) ; wakeupLock . wait ( wakeupDelta + 10 ) ; long end = System . currentTimeMillis ( ) ; if ( TraceComponent . isAnyTracingEnabled ( ) && tc . isDebugEnabled ( ) ) SibTr . debug ( tc , "Thread slept for " + ( end - start ) ) ; if ( end < nextWakeup ) setNextWakeup ( nextWakeup ) ; } } catch ( InterruptedException e ) { // No FFDC code needed // swallow InterruptedException ... we'll just loop round and try again } } } else { try { if ( ! finished ) { if ( TraceComponent . isAnyTracingEnabled ( ) && tc . isDebugEnabled ( ) ) SibTr . debug ( tc , "Thread wait : Inifinite" ) ; wakeupLock . wait ( ) ; } } catch ( InterruptedException e ) { // No FFDC code needed // swallow InterruptedException ... we'll just loop round and try again } } } // synchronized } } catch ( RuntimeException e ) { // FFDC FFDCFilter . processException ( e , "com.ibm.ws.sib.processor.utils.am.MPAlarmThread.run" , "1:284:1.8.1.7" , this ) ; SibTr . error ( tc , nls . getFormattedMessage ( "INTERNAL_MESSAGING_ERROR_CWSIP0002" , new Object [ ] { "com.ibm.ws.sib.processor.utils.am.MPAlarmThread" , "1:290:1.8.1.7" , e } , null ) ) ; if ( TraceComponent . isAnyTracingEnabled ( ) && tc . isEntryEnabled ( ) ) { SibTr . exception ( tc , e ) ; SibTr . exit ( tc , "run" , e ) ; } throw e ; } if ( TraceComponent . isAnyTracingEnabled ( ) && tc . isEntryEnabled ( ) ) SibTr . exit ( tc , "run" ) ; }
The main loop for the MPAlarmThread . Loops until the alarm thread is marked as finished . If the alarm thread is suspended it will wait forever . Otherwise the it will wait inside the loop until a specified time and then call the MPAlarmManager . fireInternalAlarm method .