public int drainTo(Collection<? super Batch> c, int n) {
synchronized (queue) {
Iterator<Batch> iter = queue.iterator();
int i;
for (i = 0; i < n && iter.hasNext(); i++) {
Batch next = iter.next();
c.add(next);
iter.remove();
size -= next.size();
queue.notify();
}
return i;
}
}