@ Override public void run ( ) { while ( ! _shutdown ) { try { Runnable task ; synchronized ( _queue ) { while ( _queue . isEmpty ( ) ) { if ( _shutdown ) { return ; } _queue . wait ( ) ; } // The double sync get/remove thing is done to support peekTask above. task = _queue . get ( 0 ) ; _queue . notifyAll ( ) ; } try { task . run ( ) ; } catch ( Exception t ) // Don't catch ThreadDeath, even though we can rethrow it, it still prints to std err, which is undesirable sometimes { log ( t ) ; } synchronized ( _queue ) { if ( _queue . size ( ) > 0 ) { _queue . removeFirst ( ) ; } } } catch ( Exception t ) // Don't catch ThreadDeath, even though we can rethrow it, it still prints to std err, which is undesirable sometimes { log ( t ) ; } } }
Do NOT ever call this! Public only by contract .