tried too fix serverSwitch synchronization problems

see also: http://www.yacy-forum.de/viewtopic.php?p=16110#16110

git-svn-id: https://svn.berlios.de/svnroot/repos/yacy/trunk@1499 6c8d7289-2bf4-0310-a012-ef5d649a1542
pull/1/head
orbiter 19 years ago
parent 3419b3bcdd
commit ec5d88664a

@ -53,6 +53,8 @@ import de.anomic.server.serverAbstractSwitch;
public abstract class serverAbstractSwitch implements serverSwitch {
private static final long delayBetweenSave = 2000;
// configuration management
private final File configFile;
private Map configProps;
@ -64,6 +66,7 @@ public abstract class serverAbstractSwitch implements serverSwitch {
private final TreeMap switchActions;
protected serverLog log;
protected int serverJobs;
private long lastTimeSaved;
public serverAbstractSwitch(String rootPath, String initPath, String configPath) {
// we initialize the switchboard with a property file,
@ -130,6 +133,9 @@ public abstract class serverAbstractSwitch implements serverSwitch {
// init busy state control
serverJobs = 0;
// save control
lastTimeSaved = System.currentTimeMillis();
}
// a logger for this switchboard
@ -147,6 +153,7 @@ public abstract class serverAbstractSwitch implements serverSwitch {
public void setConfig(String key, String value) {
// perform action before setting new value
synchronized (configProps) {
Map.Entry entry;
serverSwitchAction action;
Iterator i = switchActions.entrySet().iterator();
@ -176,8 +183,10 @@ public abstract class serverAbstractSwitch implements serverSwitch {
}
}
}
}
public String getConfig(String key, String dflt) {
synchronized (configProps) {
// get the value
Object s = configProps.get(key);
@ -196,7 +205,9 @@ public abstract class serverAbstractSwitch implements serverSwitch {
}
// return value
if (s == null) return dflt; else return (String)s;
if (s == null) return dflt;
else return (String) s;
}
}
public long getConfigLong(String key, long dflt) {
@ -212,11 +223,16 @@ public abstract class serverAbstractSwitch implements serverSwitch {
}
private void saveConfig() {
if (System.currentTimeMillis() > this.lastTimeSaved + delayBetweenSave) {
try {
synchronized (configProps) {
serverFileUtils.saveMap(configFile, configProps, configComment);
}
} catch (IOException e) {
System.out.println("ERROR: cannot write config file " + configFile.toString() + ": " + e.getMessage());
}
this.lastTimeSaved = System.currentTimeMillis();
}
}
public Map getRemoved() {

@ -433,13 +433,13 @@ public final class yacy {
run.addShutdownHook(new shutdownHookThread(Thread.currentThread(), sb));
// save information about available memory after all initializations
try {
//try {
sb.setConfig("memoryFreeAfterInitBGC", Runtime.getRuntime().freeMemory());
sb.setConfig("memoryTotalAfterInitBGC", Runtime.getRuntime().totalMemory());
System.gc();
sb.setConfig("memoryFreeAfterInitAGC", Runtime.getRuntime().freeMemory());
sb.setConfig("memoryTotalAfterInitAGC", Runtime.getRuntime().totalMemory());
} catch (ConcurrentModificationException e) {}
//} catch (ConcurrentModificationException e) {}
// wait for server shutdown
try {

Loading…
Cancel
Save