diff --git a/build.properties b/build.properties index a942cce11..acf5bde47 100644 --- a/build.properties +++ b/build.properties @@ -3,7 +3,7 @@ javacSource=1.5 javacTarget=1.5 # Release Configuration -releaseVersion=0.96 +releaseVersion=0.97 stdReleaseFile=yacy_v${releaseVersion}_${DSTAMP}_${releaseNr}.tar.gz sourceReleaseFile=yacy_src_v${releaseVersion}_${DSTAMP}_${releaseNr}.tar.gz releaseFileParentDir=yacy diff --git a/source/net/yacy/gui/YaCyApp.java b/source/net/yacy/gui/YaCyApp.java index 554e0358e..fc5b7d0cd 100644 --- a/source/net/yacy/gui/YaCyApp.java +++ b/source/net/yacy/gui/YaCyApp.java @@ -130,15 +130,15 @@ public class YaCyApp { // registering shutdown hook log.info("Registering Shutdown Hook"); - Switchboard.addShutdownHook(Thread.currentThread()); - - SwingUtilities.invokeLater(new Runnable() { + Thread t = new Thread() { public void run() { app = new Application("YaCy GUI", operation, menues, new InfoPage("localhost", 8080)); app.setLocationRelativeTo(null); app.setVisible(true); } - }); + }; + Switchboard.addShutdownHook(t, net.yacy.yacy.shutdownSemaphore); + SwingUtilities.invokeLater(t); } public static void main(String[] args) { diff --git a/source/net/yacy/gui/framework/Switchboard.java b/source/net/yacy/gui/framework/Switchboard.java index 8842c2d42..2e597d902 100644 --- a/source/net/yacy/gui/framework/Switchboard.java +++ b/source/net/yacy/gui/framework/Switchboard.java @@ -29,6 +29,7 @@ import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.IOException; import java.util.Properties; +import java.util.concurrent.Semaphore; import javax.swing.text.JTextComponent; @@ -64,10 +65,10 @@ public class Switchboard { new InfoUpdater(2000).start(); } - public static void addShutdownHook(Thread mainThread) { + public static void addShutdownHook(Thread mainThread, Semaphore semaphore) { // registering shutdown hook final Runtime run = Runtime.getRuntime(); - run.addShutdownHook(new shutdownHookThread(mainThread)); + run.addShutdownHook(new shutdownHookThread(mainThread, semaphore)); } public static JTextComponent InfoBox = null; @@ -98,14 +99,16 @@ public class Switchboard { /** * This class is a helper class whose instance is started, when the java virtual - * machine shuts down. Signals the plasmaSwitchboard to shut down. + * machine shuts down. Signals the Switchboard to shut down. */ public static class shutdownHookThread extends Thread { private final Thread mainThread; + private final Semaphore shutdownSemaphore; - public shutdownHookThread(final Thread mainThread) { + public shutdownHookThread(final Thread mainThread, Semaphore semaphore) { super(); this.mainThread = mainThread; + this.shutdownSemaphore = semaphore; } public void run() { @@ -118,10 +121,18 @@ public class Switchboard { shutdown(); // waiting for the main thread to finish execution - log.info("Waiting for main thread to finish."); + log.info("Waiting for GUI thread to finish."); + this.mainThread.interrupt(); if (this.mainThread != null && this.mainThread.isAlive()) { this.mainThread.join(); } + // wait until everything is written + log.info("Waiting for main thread to finish. shutdownSemaphore.permits = " + shutdownSemaphore.availablePermits()); + shutdownSemaphore.acquireUninterruptibly(); + //log.info("Aquired shutdown semaphore. remaining permits = " + shutdownSemaphore.availablePermits()); + + // finished + log.info("Shutdown Hook Terminated. Shutdown."); } } catch (final Exception e) { log.info("Unexpected error. " + e.getClass().getName(),e); diff --git a/source/net/yacy/yacy.java b/source/net/yacy/yacy.java index 403138291..135278a75 100644 --- a/source/net/yacy/yacy.java +++ b/source/net/yacy/yacy.java @@ -131,24 +131,13 @@ public final class yacy { public static final String vDATE = yacyBuildProperties.getBuildDate(); public static final String copyright = "[ YaCy v" + vString + ", build " + vDATE + " by Michael Christen / www.yacy.net ]"; public static final String hline = "-------------------------------------------------------------------------------"; - + public static final Semaphore shutdownSemaphore = new Semaphore(0); + /** * a reference to the {@link Switchboard} created by the * {@link yacy#startup(String, long, long)} method. */ private static Switchboard sb = null; - - /** - * Semaphore needed by {@link yacy#setUpdaterCallback(serverUpdaterCallback)} to block - * until the {@link plasmaSwitchboard }object was created. - */ - //private static serverSemaphore sbSync = new serverSemaphore(0); - - /** - * Semaphore needed by {@link yacy#waitForFinishedStartup()} to block - * until startup has finished - */ - private static Semaphore startupFinishedSync = new Semaphore(0); /** * Starts up the whole application. Sets up all datastructures and starts @@ -393,9 +382,6 @@ public final class yacy { sb.setConfig("memoryFreeAfterInitAGC", MemoryControl.free()); sb.setConfig("memoryTotalAfterInitAGC", MemoryControl.total()); //} catch (ConcurrentModificationException e) {} - - // signal finished startup - startupFinishedSync.release(); // wait for server shutdown try { @@ -438,10 +424,10 @@ public final class yacy { } catch (final Exception ee) { Log.logSevere("STARTUP", "FATAL ERROR: " + ee.getMessage(),ee); } finally { - startupFinishedSync.release(); } Log.logConfig("SHUTDOWN", "goodbye. (this is the last line)"); Log.shutdown(); + shutdownSemaphore.release(1000); try { System.exit(0); } catch (Exception e) {} // was once stopped by de.anomic.net.ftpc$sm.checkExit(ftpc.java:1790)