private void cleanup ( ) { StatsDataReference ref = null ; while ( ( ref = ( StatsDataReference ) statisticsReferenceQueue . poll ( ) ) != null ) { StatsData oldStats = null ; StatsData updatedStats = null ; do { oldStats = terminatedThreadStats . get ( ) ; updatedStats = aggregateStats ( oldStats , ref . statsData ) ; } while ( ! terminatedThreadStats . compareAndSet ( oldStats , updatedStats ) ) ; allReferences . remove ( ref ) ; } }
Poll the reference queue looking for statistics data associated with a thread that is no longer reachable . If one is found update the terminated thread statistics .