synchronize on block map access

This commit is contained in:
Jesse Boyd 2017-01-30 06:26:47 +11:00
parent 116a1869b1
commit 6408320843
No known key found for this signature in database
GPG Key ID: 59F1DE6293AF6E1F
2 changed files with 30 additions and 22 deletions

View File

@ -43,13 +43,17 @@ public class DefaultFaweQueueMap implements IFaweQueueMap {
@Override
public Collection<FaweChunk> getFaweCunks() {
return new HashSet<>(blocks.values());
synchronized (blocks) {
return new HashSet<>(blocks.values());
}
}
@Override
public void forEachChunk(RunnableVal<FaweChunk> onEach) {
for (Map.Entry<Long, FaweChunk> entry : blocks.entrySet()) {
onEach.run(entry.getValue());
synchronized (blocks) {
for (Map.Entry<Long, FaweChunk> entry : blocks.entrySet()) {
onEach.run(entry.getValue());
}
}
}

View File

@ -47,31 +47,35 @@ public class WeakFaweQueueMap implements IFaweQueueMap {
@Override
public Collection<FaweChunk> getFaweCunks() {
HashSet<FaweChunk> set = new HashSet<>();
Iterator<Map.Entry<Long, Reference<FaweChunk>>> iter = blocks.entrySet().iterator();
while (iter.hasNext()) {
Map.Entry<Long, Reference<FaweChunk>> entry = iter.next();
FaweChunk value = entry.getValue().get();
if (value != null) {
set.add(value);
} else {
Fawe.debug("Skipped modifying chunk due to low memory (1)");
iter.remove();
synchronized (blocks) {
Iterator<Map.Entry<Long, Reference<FaweChunk>>> iter = blocks.entrySet().iterator();
while (iter.hasNext()) {
Map.Entry<Long, Reference<FaweChunk>> entry = iter.next();
FaweChunk value = entry.getValue().get();
if (value != null) {
set.add(value);
} else {
Fawe.debug("Skipped modifying chunk due to low memory (1)");
iter.remove();
}
}
return set;
}
return set;
}
@Override
public void forEachChunk(RunnableVal<FaweChunk> onEach) {
Iterator<Map.Entry<Long, Reference<FaweChunk>>> iter = blocks.entrySet().iterator();
while (iter.hasNext()) {
Map.Entry<Long, Reference<FaweChunk>> entry = iter.next();
FaweChunk value = entry.getValue().get();
if (value != null) {
onEach.run(value);
} else {
Fawe.debug("Skipped modifying chunk due to low memory (2)");
iter.remove();
synchronized (blocks) {
Iterator<Map.Entry<Long, Reference<FaweChunk>>> iter = blocks.entrySet().iterator();
while (iter.hasNext()) {
Map.Entry<Long, Reference<FaweChunk>> entry = iter.next();
FaweChunk value = entry.getValue().get();
if (value != null) {
onEach.run(value);
} else {
Fawe.debug("Skipped modifying chunk due to low memory (2)");
iter.remove();
}
}
}
}