public List < E > pollBatch ( ) { lock . lock ( ) ; try { if ( open ) { if ( elements . size ( ) > 0 ) { ArrayList < E > result = new ArrayList <> ( elements ) ; elements . clear ( ) ; return result ; } else { return null ; } } else { throw new IllegalStateException ( "queue is closed" ) ; } } finally { lock . unlock ( ) ; } }
Returns all of the queue s current elements in a list if the queue is non - empty . Otherwise this method returns null .