@SuppressWarnings("unchecked") @Override public void run(){
synchronized (threadMonitorObject) {
    if (incomingQueue.isEmpty()) {
      try {
        threadMonitorObject.wait();
      }
 catch (      InterruptedException e) {
        LOGGER.error("ThreadHandler interrupted while waiting on monitor object");
      }
    }
  }
  while (handlerEnabled || !incomingQueue.isEmpty()) {
    while (!incomingQueue.isEmpty()) {
synchronized (threadMonitorObject) {
        incomingQueue.drainTo(copyList);
      }
      while (!copyList.isEmpty()) {
        try {
          methodToCall.invoke(objectToCall,copyList.pollFirst());
        }
 catch (        IllegalArgumentException e) {
          LOGGER.error("ThreadHandler passed incorrect parameters - unable to process them: {}",e.getMessage());
        }
catch (        IllegalAccessException e) {
          LOGGER.error("IllegalAccessException caught while invoking method on ThreadHandler: {}",e.getMessage());
        }
catch (        InvocationTargetException e) {
          LOGGER.error("InvocationTargetException caught while invoking method on ThreadHandler: {}",e.getMessage());
        }
catch (        Exception e) {
          LOGGER.error("Unidentified exception caught in the ThreadHandler thread: {}",e.getMessage());
        }
      }
    }
synchronized (threadMonitorObject) {
      if (incomingQueue.isEmpty()) {
        try {
          threadMonitorObject.wait();
        }
 catch (        InterruptedException e) {
          LOGGER.error("Interrupted while waiting.");
          e.printStackTrace();
        }
      }
    }
  }
}

@ SuppressWarnings ( "unchecked" ) @ Override public void run ( ) { synchronized ( threadMonitorObject ) { if ( incomingQueue . isEmpty ( ) ) { try { threadMonitorObject . wait ( ) ; } catch ( InterruptedException e ) { LOGGER . error ( "ThreadHandler interrupted while waiting on monitor object" ) ; } } } while ( handlerEnabled || ! incomingQueue . isEmpty ( ) ) { while ( ! incomingQueue . isEmpty ( ) ) { synchronized ( threadMonitorObject ) { incomingQueue . drainTo ( copyList ) ; } while ( ! copyList . isEmpty ( ) ) { try { methodToCall . invoke ( objectToCall , copyList . pollFirst ( ) ) ; } catch ( IllegalArgumentException e ) { LOGGER . error ( "ThreadHandler passed incorrect parameters - unable to process them: {}" , e . getMessage ( ) ) ; } catch ( IllegalAccessException e ) { LOGGER . error ( "IllegalAccessException caught while invoking method on ThreadHandler: {}" , e . getMessage ( ) ) ; } catch ( InvocationTargetException e ) { LOGGER . error ( "InvocationTargetException caught while invoking method on ThreadHandler: {}" , e . getMessage ( ) ) ; } catch ( Exception e ) { LOGGER . error ( "Unidentified exception caught in the ThreadHandler thread: {}" , e . getMessage ( ) ) ; } } } synchronized ( threadMonitorObject ) { if ( incomingQueue . isEmpty ( ) ) { try { threadMonitorObject . wait ( ) ; } catch ( InterruptedException e ) { LOGGER . error ( "Interrupted while waiting." ) ; e . printStackTrace ( ) ; } } } } }
start the thread . expires once shutdown has been called .
