mirror of
https://github.com/internetarchive/heritrix3.git
synced 2026-11-15 10:20:47 +00:00
* StoredQueue
(size) more robust against concurrent emptying
This commit is contained in:
1 parent
9eb0c137e8
commit
5e2e458469
1 file changed
+8
-1
@@ -22,6 +22,7 @@ package org.archive.bdb;
|
||||
import java.io.Serializable;
|
||||
import java.util.AbstractQueue;
|
||||
import java.util.Iterator;
|
||||
import java.util.NoSuchElementException;
|
||||
import java.util.concurrent.atomic.AtomicLong;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
@@ -92,9 +93,15 @@ public class StoredQueue<E extends Serializable> extends AbstractQueue<E> {
|
||||
@Override
|
||||
public int size() {
|
||||
try {
|
||||
return queueMap.isEmpty() ? 0 : (int)(tailIndex.get() - queueMap.firstKey());
|
||||
return Math.max(0,
|
||||
(int)(tailIndex.get()
|
||||
- queueMap.firstKey()));
|
||||
} catch (IllegalStateException ise) {
|
||||
return 0;
|
||||
} catch (NoSuchElementException nse) {
|
||||
return 0;
|
||||
} catch (NullPointerException npe) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user