src/org/sonews/ShutdownHook.java
changeset 37 74139325d305
parent 35 ed84c8bdd87b
child 49 8df94bfd3e2f
     1.1 --- a/src/org/sonews/ShutdownHook.java	Sun Aug 29 17:28:58 2010 +0200
     1.2 +++ b/src/org/sonews/ShutdownHook.java	Sun Aug 29 18:17:37 2010 +0200
     1.3 @@ -30,55 +30,44 @@
     1.4  class ShutdownHook extends Thread
     1.5  {
     1.6  
     1.7 -  /**
     1.8 -   * Called when the JVM exits.
     1.9 -   */
    1.10 -  @Override
    1.11 -  public void run()
    1.12 -  {
    1.13 -    System.out.println("sonews: Trying to shutdown all threads...");
    1.14 +	/**
    1.15 +	 * Called when the JVM exits.
    1.16 +	 */
    1.17 +	@Override
    1.18 +	public void run()
    1.19 +	{
    1.20 +		System.out.println("sonews: Trying to shutdown all threads...");
    1.21  
    1.22 -    Map<Thread, StackTraceElement[]> threadsMap = Thread.getAllStackTraces();
    1.23 -    for(Thread thread : threadsMap.keySet())
    1.24 -    {
    1.25 -      // Interrupt the thread if it's a AbstractDaemon
    1.26 -      AbstractDaemon daemon;
    1.27 -      if(thread instanceof AbstractDaemon && thread.isAlive())
    1.28 -      {
    1.29 -        try
    1.30 -        {
    1.31 -          daemon = (AbstractDaemon)thread;
    1.32 -          daemon.shutdownNow();
    1.33 -        }
    1.34 -        catch(SQLException ex)
    1.35 -        {
    1.36 -          System.out.println("sonews: " + ex);
    1.37 -        }
    1.38 -      }
    1.39 -    }
    1.40 -    
    1.41 -    for(Thread thread : threadsMap.keySet())
    1.42 -    {
    1.43 -      AbstractDaemon daemon;
    1.44 -      if(thread instanceof AbstractDaemon && thread.isAlive())
    1.45 -      {
    1.46 -        daemon = (AbstractDaemon)thread;
    1.47 -        System.out.println("sonews: Waiting for " + daemon + " to exit...");
    1.48 -        try
    1.49 -        {
    1.50 -          daemon.join(500);
    1.51 -        }
    1.52 -        catch(InterruptedException ex)
    1.53 -        {
    1.54 -          System.out.println(ex.getLocalizedMessage());
    1.55 -        }
    1.56 -      }
    1.57 -    }
    1.58 -    
    1.59 -    // We have notified all not-sleeping AbstractDaemons of the shutdown;
    1.60 -    // all other threads can be simply purged on VM shutdown
    1.61 -    
    1.62 -    System.out.println("sonews: Clean shutdown.");
    1.63 -  }
    1.64 -  
    1.65 +		Map<Thread, StackTraceElement[]> threadsMap = Thread.getAllStackTraces();
    1.66 +		for (Thread thread : threadsMap.keySet()) {
    1.67 +			// Interrupt the thread if it's a AbstractDaemon
    1.68 +			AbstractDaemon daemon;
    1.69 +			if (thread instanceof AbstractDaemon && thread.isAlive()) {
    1.70 +				try {
    1.71 +					daemon = (AbstractDaemon) thread;
    1.72 +					daemon.shutdownNow();
    1.73 +				} catch (SQLException ex) {
    1.74 +					System.out.println("sonews: " + ex);
    1.75 +				}
    1.76 +			}
    1.77 +		}
    1.78 +
    1.79 +		for (Thread thread : threadsMap.keySet()) {
    1.80 +			AbstractDaemon daemon;
    1.81 +			if (thread instanceof AbstractDaemon && thread.isAlive()) {
    1.82 +				daemon = (AbstractDaemon) thread;
    1.83 +				System.out.println("sonews: Waiting for " + daemon + " to exit...");
    1.84 +				try {
    1.85 +					daemon.join(500);
    1.86 +				} catch (InterruptedException ex) {
    1.87 +					System.out.println(ex.getLocalizedMessage());
    1.88 +				}
    1.89 +			}
    1.90 +		}
    1.91 +
    1.92 +		// We have notified all not-sleeping AbstractDaemons of the shutdown;
    1.93 +		// all other threads can be simply purged on VM shutdown
    1.94 +
    1.95 +		System.out.println("sonews: Clean shutdown.");
    1.96 +	}
    1.97  }