*) further improvements in shutdown behaviour

git-svn-id: https://svn.berlios.de/svnroot/repos/yacy/trunk@391 6c8d7289-2bf4-0310-a012-ef5d649a1542
pull/1/head
theli 20 years ago
parent 0b95c9c434
commit 96386d6fc6

@ -225,6 +225,7 @@ public abstract class serverAbstractThread extends Thread implements serverThrea
// do job
timestamp = System.currentTimeMillis();
isBusy = this.job();
if ((!running) || (this.isInterrupted())) break;
busytime += (isBusy) ? System.currentTimeMillis() - timestamp : 0;
// interrupt loop if this is supposed to be a one-time job
if ((this.idlePause < 0) || (this.busyPause < 0)) break; // for one-time jobs
@ -253,14 +254,6 @@ public abstract class serverAbstractThread extends Thread implements serverThrea
}
private void ratz(long millis) {
// int loop = 1;
// while (millis > 1000) {
// loop = loop * 2;
// millis = millis / 2;
// }
// while ((loop-- > 0) && (running)) {
// try {this.sleep(millis);} catch (InterruptedException e) {}
// }
try {
if (this.syncObject != null) {
synchronized(this.syncObject) {

@ -429,7 +429,10 @@ public final class serverCore extends serverAbstractThread implements serverThre
// closing the port forwarding channel
if ((portForwardingEnabled) && (portForwarding != null) ) {
try {
this.log.logInfo("Shutdown port forwarding ...");
portForwarding.disconnect();
portForwardingEnabled = false;
portForwarding = null;
} catch (Exception e) {
this.log.logWarning("Unable to shutdown the port forwarding channel.");
}
@ -437,6 +440,7 @@ public final class serverCore extends serverAbstractThread implements serverThre
// closing the serverchannel and socket
try {
this.log.logInfo("Closing server socket ...");
this.socket.close();
} catch (Exception e) {
this.log.logWarning("Unable to close the server socket.");
@ -444,6 +448,7 @@ public final class serverCore extends serverAbstractThread implements serverThre
// closing the session pool
try {
this.log.logInfo("Closing server session pool ...");
this.theSessionPool.close();
} catch (Exception e) {
this.log.logWarning("Unable to close the session pool.");
@ -502,6 +507,7 @@ public final class serverCore extends serverAbstractThread implements serverThre
/*
* shutdown all still running session threads ...
*/
this.isClosed = true;
/* waiting for all threads to finish */
int threadCount = serverCore.this.theSessionThreadGroup.activeCount();
@ -516,34 +522,37 @@ public final class serverCore extends serverAbstractThread implements serverThre
}
// interrupting all still running or pooled threads ...
serverCore.this.log.logInfo("Sending interruption signal to " + threadCount + " remaining session threads ...");
serverCore.this.log.logInfo("Sending interruption signal to " + serverCore.this.theSessionThreadGroup.activeCount() + " remaining session threads ...");
serverCore.this.theSessionThreadGroup.interrupt();
// waiting a frew ms for the session objects to continue processing
Thread.sleep(500);
try { Thread.sleep(500); } catch (InterruptedException ex) {}
// if there are some sessions that are blocking in IO, we simply close the socket
serverCore.this.log.logDebug("Trying to abort " + serverCore.this.theSessionThreadGroup.activeCount() + " remaining session threads ...");
for ( int currentThreadIdx = 0; currentThreadIdx < threadCount; currentThreadIdx++ ) {
serverCore.this.log.logInfo("Trying to shutdown session thread '" + threadList[currentThreadIdx].getName() + "'.");
((Session)threadList[currentThreadIdx]).close();
Thread currentThread = threadList[currentThreadIdx];
if (currentThread.isAlive()) {
serverCore.this.log.logInfo("Trying to shutdown session thread '" + currentThread.getName() + "' [" + currentThreadIdx + "].");
((Session)currentThread).close();
}
}
// we need to use a timeout here because of missing interruptable session threads ...
serverCore.this.log.logDebug("Waiting for " + serverCore.this.theSessionThreadGroup.activeCount() + " remaining session threads to finish shutdown ...");
for ( int currentThreadIdx = 0; currentThreadIdx < threadCount; currentThreadIdx++ ) {
if (threadList[currentThreadIdx].isAlive()) {
serverCore.this.log.logDebug("Waiting for session thread '" + threadList[currentThreadIdx].getName() + "' to finish shutdown.");
try {
threadList[currentThreadIdx].join(500);
} catch (Exception ex) {}
Thread currentThread = threadList[currentThreadIdx];
if (currentThread.isAlive()) {
serverCore.this.log.logDebug("Waiting for session thread '" + currentThread.getName() + "' [" + currentThreadIdx + "] to finish shutdown.");
try { currentThread.join(500); } catch (InterruptedException ex) {}
}
}
} catch (InterruptedException e) {
serverCore.this.log.logWarning("Interruption while trying to shutdown all remaining session threads.");
serverCore.this.log.logInfo("Shutdown of remaining session threads finish.");
} catch (Exception e) {
serverCore.this.log.logError("Unexpected error while trying to shutdown all remaining session threads.",e);
}
this.isClosed = true;
super.close();
}
@ -714,7 +723,7 @@ public final class serverCore extends serverAbstractThread implements serverThre
public void log(boolean outgoing, String request) {
serverCore.this.log.logDebug(userAddress.getHostAddress() + "/" + this.identity + " " +
"[" + serverCore.this.theSessionPool.getNumActive() + ", " + this.commandCounter +
"[" + ((serverCore.this.theSessionPool.isClosed)? -1 : serverCore.this.theSessionPool.getNumActive()) + ", " + this.commandCounter +
((outgoing) ? "] > " : "] < ") +
request);
}

@ -478,27 +478,40 @@ public class yacyCore {
yacyCore.publishThreadGroup.interrupt();
// waiting some time for the publishThreads to finish execution
try { Thread.sleep(500); } catch (Exception ex) {}
try { Thread.sleep(500); } catch (InterruptedException ex) {}
// getting the amount of remaining publishing threads
int threadCount = yacyCore.publishThreadGroup.activeCount();
Thread[] threadList = new Thread[threadCount];
threadCount = yacyCore.publishThreadGroup.enumerate(threadList);
// we need to use a timeout here because of missing interruptable session threads ...
log.logDebug("publish: Trying to abort " + yacyCore.publishThreadGroup.activeCount() + " remaining publishing threads ...");
for ( int currentThreadIdx = 0; currentThreadIdx < threadCount; currentThreadIdx++ ) {
Thread currentThread = threadList[currentThreadIdx];
if (currentThread.isAlive()) {
log.logInfo("publish: Closing socket of publishing thread '" + threadList[currentThreadIdx].getName() + "'.");
log.logDebug("publish: Closing socket of publishing thread '" + currentThread.getName() + "' [" + currentThreadIdx + "].");
httpc.closeOpenSockets(currentThread);
}
}
log.logInfo("publish: Waiting for remaining publishing thread '" + threadList[currentThreadIdx].getName() + "' to finish shutdown");
try { threadList[currentThreadIdx].join(500); }catch (Exception ex) {}
// we need to use a timeout here because of missing interruptable session threads ...
log.logDebug("publish: Waiting for " + yacyCore.publishThreadGroup.activeCount() + " remaining publishing threads to finish shutdown ...");
for ( int currentThreadIdx = 0; currentThreadIdx < threadCount; currentThreadIdx++ ) {
Thread currentThread = threadList[currentThreadIdx];
if (currentThread.isAlive()) {
log.logDebug("publish: Waiting for remaining publishing thread '" + currentThread.getName() + "' to finish shutdown");
try { currentThread.join(500); }catch (InterruptedException ex) {}
}
}
log.logInfo("publish: Shutdown off all remaining publishing thread finished.");
}
catch (Exception ee) {
log.logWarning("publish: Interruption while trying to shutdown all remaining publishing threads.");
log.logWarning("publish: Unexpected error while trying to shutdown all remaining publishing threads.",e);
}
return 0;

Loading…
Cancel
Save