private void check ( ) { for ( final Map . Entry < Thread , Long > entry : this . threads . entrySet ( ) ) { final long time = System . currentTimeMillis ( ) ; if ( time - entry . getValue ( ) > this . latency ) { final Thread thread = entry . getKey ( ) ; if ( thread . isAlive ( ) ) { thread . interrupt ( ) ; } this . threads . remove ( thread ) ; } } }
Checking threads storage and interrupt long running threads .