added index check to prevent blocking in synchronization

git-svn-id: https://svn.berlios.de/svnroot/repos/yacy/trunk@6832 6c8d7289-2bf4-0310-a012-ef5d649a1542
pull/1/head
orbiter 15 years ago
parent 65f383e70b
commit cff8ed134f

@ -96,10 +96,14 @@ public class HeapModifier extends HeapReader implements BLOB {
*/
public void remove(byte[] key) throws IOException {
key = normalizeKey(key);
// pre-check before synchronization
long seek = index.get(key);
if (seek < 0) return;
synchronized (this) {
// check if the index contains the key
final long seek = index.get(key);
// check again if the index contains the key
seek = index.get(key);
if (seek < 0) return;
// check consistency of the index
@ -238,10 +242,14 @@ public class HeapModifier extends HeapReader implements BLOB {
public int replace(byte[] key, final Rewriter rewriter) throws IOException {
key = normalizeKey(key);
assert key.length == this.keylength;
synchronized (this) {
// check if the index contains the key
final long pos = index.get(key);
// pre-check before synchronization
long pos = index.get(key);
if (pos < 0) return 0;
synchronized (this) {
// check again if the index contains the key
pos = index.get(key);
if (pos < 0) return 0;
// check consistency of the index

Loading…
Cancel
Save