preparation for intermission feature (pausing all threads, i.e. for search requests)

git-svn-id: https://svn.berlios.de/svnroot/repos/yacy/trunk@509 6c8d7289-2bf4-0310-a012-ef5d649a1542
pull/1/head
orbiter 20 years ago
parent ee0a9a2d9b
commit 6be19d76c9

@ -293,6 +293,13 @@ public abstract class serverAbstractSwitch implements serverSwitch {
} }
} }
public void intermissionAllThreads(long pause) {
Iterator e = workerThreads.keySet().iterator();
while (e.hasNext()) {
((serverThread) workerThreads.get((String) e.next())).intermission(pause);
}
}
public synchronized void terminateAllThreads(boolean waitFor) { public synchronized void terminateAllThreads(boolean waitFor) {
Iterator e = workerThreads.keySet().iterator(); Iterator e = workerThreads.keySet().iterator();
while (e.hasNext()) { while (e.hasNext()) {

@ -54,7 +54,7 @@ import de.anomic.server.logging.serverLog;
public abstract class serverAbstractThread extends Thread implements serverThread { public abstract class serverAbstractThread extends Thread implements serverThread {
private long startup = 0, idlePause = 0, busyPause = 0, blockPause = 0; private long startup = 0, intermission = 0, idlePause = 0, busyPause = 0, blockPause = 0;
private boolean running = true; private boolean running = true;
private serverLog log = null; private serverLog log = null;
private long idletime = 0, busytime = 0, memprereq = 0; private long idletime = 0, busytime = 0, memprereq = 0;
@ -163,6 +163,10 @@ public abstract class serverAbstractThread extends Thread implements serverThrea
this.log = log; this.log = log;
} }
public void intermission(long pause) {
this.intermission = System.currentTimeMillis() + pause;
}
public void terminate(boolean waitFor) { public void terminate(boolean waitFor) {
// after calling this method, the thread shall terminate // after calling this method, the thread shall terminate
this.running = false; this.running = false;
@ -227,6 +231,12 @@ public abstract class serverAbstractThread extends Thread implements serverThrea
Runtime rt = Runtime.getRuntime(); Runtime rt = Runtime.getRuntime();
while (running) { while (running) {
if (this.intermission > 0) {
if (this.intermission > System.currentTimeMillis()) {
ratz(System.currentTimeMillis() - this.intermission);
}
this.intermission = 0;
}
if (rt.freeMemory() > memprereq) try { if (rt.freeMemory() > memprereq) try {
// do job // do job
timestamp = System.currentTimeMillis(); timestamp = System.currentTimeMillis();

@ -79,7 +79,9 @@ public interface serverSwitch {
public serverThread getThread(String threadName); public serverThread getThread(String threadName);
public void setThreadPerformance(String threadName, long idleMillis, long busyMillis, long memprereq); public void setThreadPerformance(String threadName, long idleMillis, long busyMillis, long memprereq);
public void terminateThread(String threadName, boolean waitFor); public void terminateThread(String threadName, boolean waitFor);
public void intermissionAllThreads(long pause);
public void terminateAllThreads(boolean waitFor); public void terminateAllThreads(boolean waitFor);
public Iterator /*of serverThread-Names (String)*/ threadNames(); public Iterator /*of serverThread-Names (String)*/ threadNames();
// the switchboard can be used to set and read properties // the switchboard can be used to set and read properties

@ -102,6 +102,10 @@ public interface serverThread {
public void jobExceptionHandler(Exception e); public void jobExceptionHandler(Exception e);
// handles any action necessary during job execution // handles any action necessary during job execution
public void intermission(long pause);
// the thread is forced to pause for a specific time
// if the thread is busy meanwhile, the pause is ommitted
public void terminate(boolean waitFor); public void terminate(boolean waitFor);
// after calling this method, the thread shall terminate // after calling this method, the thread shall terminate
// if waitFor is true, the method waits until the process has died // if waitFor is true, the method waits until the process has died

Loading…
Cancel
Save