public int drainTo ( Collection < ? super Task > c ) { if ( c == this ) throw new IllegalArgumentException ( "cannot drain task set into itself" ) ; if ( c == null ) throw new NullPointerException ( "target collection must not be null" ) ; int count = 0 ; while ( true ) { try { Task t = this . poll ( 0 , TimeUnit . SECONDS ) ; if ( t == null ) break ; else c . add ( t ) ; } catch ( InterruptedException e ) { break ; } } return count ; }
Removes all available elements from this task set . Any tasks that are blocked will not be removed . Will cease draining if the thread is interrupted .