public void poll ( ) { synchronized ( queue ) { // Remove queued references. // (Is this better inside or out?) if ( queue . poll ( ) == null ) { // Nothing to do. return ; } while ( queue . poll ( ) != null ) { // Discard. } // Remove any dead holders. Holder first = strongRefs ; if ( first == null ) { // Unlikely... return ; } Holder link = first ; Holder next = link . next ; while ( next != null ) { if ( next . get ( ) == null ) { next = next . next ; link . next = next ; } else { link = next ; next = next . next ; } } // Remove dead head, possibly. if ( first . get ( ) == null ) { if ( ! strongRefsUpdater . weakCompareAndSet ( this , first , first . next ) ) { // Something else has come along. // Just null out - next search will remove it. first . value = null ; } } } }
Check if any strong references need should be removed due to thread exit .