src/main/java/org/jboss/util/threadpool/BasicThreadPool.java
/** The monitor thread loops until the pool is shutdown. It waits for
       * tasks with completion timeouts and sleeps until the next completion
       * timeout and then interrupts the associated task thread, and invokes
       * stopTask on the TaskWrapper. A new timeout check is then inserted with
       * a 1 second timeout to validate that the TaskWrapper has exited the
       * run method. If it has not, then the associated task thread is stopped
       * using the deprecated Thread.stop method since this is the only way to
       * abort a thread that is in spin loop for example.
       * 
       * @todo this is not responsive to new tasks with timeouts smaller than
       * the current shortest completion expiration. We probably should interrupt
       * the thread on each insertion into the timeout heap to ensure better
       * responsiveness.
       */
The monitor thread loops until the pool is shutdown. It waits for
tasks with completion timeouts and sleeps until the next completion
timeout and then interrupts the associated task thread, and invokes
stopTask on the TaskWrapper. A new timeout check is then inserted with
a 1 second timeout to validate that the TaskWrapper has exited the
run method. If it has not, then the associated task thread is stopped
using the deprecated Thread.stop method since this is the only way to
abort a thread that is in spin loop for example.

@todo this is not responsive to new tasks with timeouts smaller than
the current shortest completion expiration. We probably should interrupt
the thread on each insertion into the timeout heap to ensure better
responsiveness.
The monitor thread loops until the pool is shutdown . It waits for tasks with completion timeouts and sleeps until the next completion timeout and then interrupts the associated task thread and invokes stopTask on the TaskWrapper . A new timeout check is then inserted with a 1 second timeout to validate that the TaskWrapper has exited the run method . If it has not then the associated task thread is stopped using the deprecated Thread . stop method since this is the only way to abort a thread that is in spin loop for example . @todo this is not responsive to new tasks with timeouts smaller than the current shortest completion expiration . We probably should interrupt the thread on each insertion into the timeout heap to ensure better responsiveness .
public void run()
      {
         boolean isStopped = stopped.get();
         while( isStopped == false )
         {
            boolean trace = log.isTraceEnabled();
            try
            {
               TimeoutInfo info = getNextTimeout();
               if( info != null )
               {
                  long now = System.currentTimeMillis();
                  long timeToTimeout = info.getTaskCompletionTimeout(now);
                  if( timeToTimeout > 0 )
                  {
                     if( trace )
                     {
                        log.trace("Will check wrapper="+info.getTaskWrapper()
                           +" after "+timeToTimeout);
                     }
                     Thread.sleep(timeToTimeout);
                  }
                  TaskWrapper wrapper = info.getTaskWrapper();
                  if( wrapper.isComplete() == false )
                  {
                     if( trace )
                        log.trace("Failed completion check for wrapper="+wrapper);
                     if( info.stopTask() == true )
                     {
                        info.setTimeout(1000);
                        tasksWithTimeouts.add(info);
                        if( trace )
                           log.trace("Rescheduled completion check for wrapper="+wrapper);
                     }
                  }
               }
               else
               {
                  Thread.sleep(1000);
               }
            }
            catch(InterruptedException e)
            {
               log.debug("Timeout monitor has been interrupted", e);
            }
            catch(Throwable e)
            {
               log.debug("Timeout monitor saw unexpected error", e);               
            }
            isStopped = stopped.get();            
         }
      }
public void run ( ) { boolean isStopped = stopped . get ( ) ; while ( isStopped == false ) { boolean trace = log . isTraceEnabled ( ) ; try { TimeoutInfo info = getNextTimeout ( ) ; if ( info != null ) { long now = System . currentTimeMillis ( ) ; long timeToTimeout = info . getTaskCompletionTimeout ( now ) ; if ( timeToTimeout > 0 ) { if ( trace ) { log . trace ( "Will check wrapper=" + info . getTaskWrapper ( ) + " after " + timeToTimeout ) ; } Thread . sleep ( timeToTimeout ) ; } TaskWrapper wrapper = info . getTaskWrapper ( ) ; if ( wrapper . isComplete ( ) == false ) { if ( trace ) log . trace ( "Failed completion check for wrapper=" + wrapper ) ; if ( info . stopTask ( ) == true ) { info . setTimeout ( 1000 ) ; tasksWithTimeouts . add ( info ) ; if ( trace ) log . trace ( "Rescheduled completion check for wrapper=" + wrapper ) ; } } } else { Thread . sleep ( 1000 ) ; } } catch ( InterruptedException e ) { log . debug ( "Timeout monitor has been interrupted" , e ) ; } catch ( Throwable e ) { log . debug ( "Timeout monitor saw unexpected error" , e ) ; } isStopped = stopped . get ( ) ; } }
The monitor thread loops until the pool is shutdown.
The monitor thread loops until the pool is shutdown .
// Check the status of the task // Requeue the TimeoutInfo to see that the task exits run