Author: xor
Date: 2008-12-14 12:53:12 +0000 (Sun, 14 Dec 2008)
New Revision: 24306

Modified:
   trunk/freenet/src/freenet/support/TransferThread.java
Log:
Implement proper terminate() function for TransferThread. Using join() was 
wrong according to nextgens and toad.

Modified: trunk/freenet/src/freenet/support/TransferThread.java
===================================================================
--- trunk/freenet/src/freenet/support/TransferThread.java       2008-12-14 
12:33:35 UTC (rev 24305)
+++ trunk/freenet/src/freenet/support/TransferThread.java       2008-12-14 
12:53:12 UTC (rev 24306)
@@ -28,6 +28,7 @@
        private Thread mThread;
        
        private volatile boolean isRunning = false;
+       private volatile boolean shutdownFinished = false;
        
        private final Collection<ClientGetter> mFetches = createFetchStorage();
        private final Collection<BaseClientPutter> mInserts = 
createInsertStorage();
@@ -56,6 +57,7 @@
                        mThread.interrupt();
                }
                
+               try {
                while(isRunning) {
                        Thread.interrupted();
                        
@@ -67,8 +69,15 @@
                                mThread.interrupt();
                        }
                }
+               }
                
-               abortAllTransfers();
+               finally {
+                       abortAllTransfers();
+                       synchronized (this) {
+                               shutdownFinished = true;
+                               notify();
+                       }
+               }
        }
        
        protected void abortAllTransfers() {
@@ -122,13 +131,17 @@
        public void terminate() {
                isRunning = false;
                mThread.interrupt();
-               try {
-                       mThread.join();
+               
+               synchronized(this) {
+                       while(!shutdownFinished) {
+                               try {
+                                       wait();
+                               }
+                               catch (InterruptedException e) {
+                                       Thread.interrupted();
+                               }
+                       }
                }
-               catch(InterruptedException e)
-               {
-                       Thread.currentThread().interrupt();
-               }
        }
        
        

_______________________________________________
cvs mailing list
[email protected]
http://emu.freenetproject.org/cgi-bin/mailman/listinfo/cvs

Reply via email to