private void evictMap ( SampleableConcurrentHashMap < ? , ? > map , int triggeringEvictionSize , int afterEvictionSize ) { map . purgeStaleEntries ( ) ; int mapSize = map . size ( ) ; if ( mapSize - triggeringEvictionSize >= 0 ) { for ( SampleableConcurrentHashMap . SamplingEntry entry : map . getRandomSamples ( mapSize - afterEvictionSize ) ) { map . remove ( entry . getEntryKey ( ) ) ; } } }
It works on best effort basis . If multi - threaded calls involved it may evict all elements but it s unlikely .