*) 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 // do job
timestamp = System.currentTimeMillis(); timestamp = System.currentTimeMillis();
isBusy = this.job(); isBusy = this.job();
if ((!running) || (this.isInterrupted())) break;
busytime += (isBusy) ? System.currentTimeMillis() - timestamp : 0; busytime += (isBusy) ? System.currentTimeMillis() - timestamp : 0;
// interrupt loop if this is supposed to be a one-time job // interrupt loop if this is supposed to be a one-time job
if ((this.idlePause < 0) || (this.busyPause < 0)) break; // for one-time jobs 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) { 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 { try {
if (this.syncObject != null) { if (this.syncObject != null) {
synchronized(this.syncObject) { synchronized(this.syncObject) {

@ -429,7 +429,10 @@ public final class serverCore extends serverAbstractThread implements serverThre
// closing the port forwarding channel // closing the port forwarding channel
if ((portForwardingEnabled) && (portForwarding != null) ) { if ((portForwardingEnabled) && (portForwarding != null) ) {
try { try {
this.log.logInfo("Shutdown port forwarding ...");
portForwarding.disconnect(); portForwarding.disconnect();
portForwardingEnabled = false;
portForwarding = null;
} catch (Exception e) { } catch (Exception e) {
this.log.logWarning("Unable to shutdown the port forwarding channel."); 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 // closing the serverchannel and socket
try { try {
this.log.logInfo("Closing server socket ...");
this.socket.close(); this.socket.close();
} catch (Exception e) { } catch (Exception e) {
this.log.logWarning("Unable to close the server socket."); 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 // closing the session pool
try { try {
this.log.logInfo("Closing server session pool ...");
this.theSessionPool.close(); this.theSessionPool.close();
} catch (Exception e) { } catch (Exception e) {
this.log.logWarning("Unable to close the session pool."); 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 ... * shutdown all still running session threads ...
*/ */
this.isClosed = true;
/* waiting for all threads to finish */ /* waiting for all threads to finish */
int threadCount = serverCore.this.theSessionThreadGroup.activeCount(); 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 ... // 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(); serverCore.this.theSessionThreadGroup.interrupt();
// waiting a frew ms for the session objects to continue processing // 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 // 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++ ) { for ( int currentThreadIdx = 0; currentThreadIdx < threadCount; currentThreadIdx++ ) {
serverCore.this.log.logInfo("Trying to shutdown session thread '" + threadList[currentThreadIdx].getName() + "'."); Thread currentThread = threadList[currentThreadIdx];
((Session)threadList[currentThreadIdx]).close(); 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 ... // 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++ ) { for ( int currentThreadIdx = 0; currentThreadIdx < threadCount; currentThreadIdx++ ) {
if (threadList[currentThreadIdx].isAlive()) { Thread currentThread = threadList[currentThreadIdx];
serverCore.this.log.logDebug("Waiting for session thread '" + threadList[currentThreadIdx].getName() + "' to finish shutdown."); if (currentThread.isAlive()) {
try { serverCore.this.log.logDebug("Waiting for session thread '" + currentThread.getName() + "' [" + currentThreadIdx + "] to finish shutdown.");
threadList[currentThreadIdx].join(500); try { currentThread.join(500); } catch (InterruptedException ex) {}
} catch (Exception 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) { } catch (Exception e) {
serverCore.this.log.logError("Unexpected error while trying to shutdown all remaining session threads.",e); serverCore.this.log.logError("Unexpected error while trying to shutdown all remaining session threads.",e);
} }
this.isClosed = true;
super.close(); super.close();
} }
@ -714,7 +723,7 @@ public final class serverCore extends serverAbstractThread implements serverThre
public void log(boolean outgoing, String request) { public void log(boolean outgoing, String request) {
serverCore.this.log.logDebug(userAddress.getHostAddress() + "/" + this.identity + " " + 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) ? "] > " : "] < ") + ((outgoing) ? "] > " : "] < ") +
request); request);
} }

@ -478,27 +478,40 @@ public class yacyCore {
yacyCore.publishThreadGroup.interrupt(); yacyCore.publishThreadGroup.interrupt();
// waiting some time for the publishThreads to finish execution // 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(); int threadCount = yacyCore.publishThreadGroup.activeCount();
Thread[] threadList = new Thread[threadCount]; Thread[] threadList = new Thread[threadCount];
threadCount = yacyCore.publishThreadGroup.enumerate(threadList); threadCount = yacyCore.publishThreadGroup.enumerate(threadList);
// we need to use a timeout here because of missing interruptable session threads ... // 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++ ) { for ( int currentThreadIdx = 0; currentThreadIdx < threadCount; currentThreadIdx++ ) {
Thread currentThread = threadList[currentThreadIdx]; Thread currentThread = threadList[currentThreadIdx];
if (currentThread.isAlive()) { 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); 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) { 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; return 0;

Loading…
Cancel
Save