Distributed Peer-to-Peer Web Search Engine and Intranet Search Appliance
Java decentralizedintranet-searchintranet-search-enginep2pp2p-networkprivacyprivacy-protectionsearch-enginesearchenginewebweb-search-enginewebsearchwebseearch-engine
*) further improvements in shutdown behaviour
theli96386d6fc624
diff --git a/source/de/anomic/server/serverAbstractThread.java b/source/de/anomic/server/serverAbstractThread.javaindex b4ab87af3..1901b118c 100644--- a/source/de/anomic/server/serverAbstractThread.java+++ b/source/de/anomic/server/serverAbstractThread.java@@ -225,6 +225,7 @@ public abstract class serverAbstractThread extends Thread implements serverThrea// do jobtimestamp = 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 jobif ((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) {diff --git a/source/de/anomic/server/serverCore.java b/source/de/anomic/server/serverCore.javaindex bab9b8942..636032a79 100644--- a/source/de/anomic/server/serverCore.java+++ b/source/de/anomic/server/serverCore.java@@ -429,7 +429,10 @@ public final class serverCore extends serverAbstractThread implements serverThre// closing the port forwarding channelif ((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 sockettry {+ 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 pooltry {+ 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 serverThrepublic 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);}diff --git a/source/de/anomic/yacy/yacyCore.java b/source/de/anomic/yacy/yacyCore.javaindex 9b4e0ae08..5d1362eb7 100644--- a/source/de/anomic/yacy/yacyCore.java+++ b/source/de/anomic/yacy/yacyCore.java@@ -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 threadsint 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;