fixed setting of shortMemoryStatus in MemoryControl

pull/1/head
Michael Peter Christen 11 years ago
parent 7e71dcc417
commit acc8d7faa7

@ -29,6 +29,7 @@ import java.lang.management.ManagementFactory;
import java.lang.management.MemoryMXBean;
import java.lang.management.MemoryPoolMXBean;
import java.lang.management.MemoryUsage;
import java.util.concurrent.atomic.AtomicBoolean;
public class GenerationMemoryStrategy extends MemoryStrategy {
@ -102,11 +103,11 @@ public class GenerationMemoryStrategy extends MemoryStrategy {
* @param force specifies whether ignoring preferred size
* @return whether enough memory could be freed (or is free) or not
*/
protected final boolean request(final long size, final boolean force, boolean shortStatus) {
protected final boolean request(final long size, final boolean force, AtomicBoolean shortStatus) {
if (size == 0l) return true; // does not make sense to check - returning true without setting shortStatus (which also doesn't make sense to me)
final boolean unknown = size < 0l; // size < 0 indicate an unknown size - maybe from gziped streams
final boolean r = unknown? properState(force) : size < available(force);
shortStatus = !r;
final boolean r = unknown ? properState(force) : size < available(force);
shortStatus.set(!r);
return r;
}

@ -26,13 +26,15 @@
package net.yacy.kelondro.util;
import java.lang.management.ManagementFactory;
import java.util.concurrent.atomic.AtomicBoolean;
/**
* Use this to get information about memory usage or try to free some memory
*/
public class MemoryControl {
private static boolean shortStatus = false, simulatedShortStatus = false, usingStandardStrategy = true;
private static AtomicBoolean shortStatus = new AtomicBoolean(false);
private static boolean simulatedShortStatus = false, usingStandardStrategy = true;
private static MemoryStrategy strategy;
private static MemoryStrategy getStrategy() {
@ -145,7 +147,7 @@ public class MemoryControl {
*/
public static boolean shortStatus() {
//if (shortStatus) System.out.println("**** SHORT MEMORY ****");
return simulatedShortStatus || shortStatus;
return simulatedShortStatus || shortStatus.get();
}
/**

@ -25,6 +25,8 @@
package net.yacy.kelondro.util;
import java.util.concurrent.atomic.AtomicBoolean;
import net.yacy.cora.util.ConcurrentLog;
public abstract class MemoryStrategy {
@ -115,7 +117,7 @@ public abstract class MemoryStrategy {
* @param force specifies whether a GC should be run even in case former GCs didn't provide enough memory
* @return whether enough memory could be freed (or is free) or not
*/
protected abstract boolean request(final long size, final boolean force, boolean shortStatus);
protected abstract boolean request(final long size, final boolean force, AtomicBoolean shortStatus);
/**
* @return if Memory seams to be in a proper state

@ -25,6 +25,8 @@
package net.yacy.kelondro.util;
import java.util.concurrent.atomic.AtomicBoolean;
import net.yacy.cora.util.Memory;
/**
@ -146,10 +148,10 @@ public class StandardMemoryStrategy extends MemoryStrategy {
* @return whether enough memory could be freed (or is free) or not
*/
@Override
protected boolean request(final long size, final boolean force, boolean shortStatus) {
protected boolean request(final long size, final boolean force, AtomicBoolean shortStatus) {
if (size <= 0) return true;
final boolean r = request0(size, force);
shortStatus = !r;
shortStatus.set(!r);
return r;
}
private boolean request0(final long size, final boolean force) {

Loading…
Cancel
Save