experimental thread-killing capabilities
authoradam <adam@megacz.com>
Sat, 30 Oct 2004 22:53:06 +0000 (22:53 +0000)
committeradam <adam@megacz.com>
Sat, 30 Oct 2004 22:53:06 +0000 (22:53 +0000)
darcs-hash:20041030225306-5007d-2386beb7236cf7c85652ece80d0f47c24c5f7178.gz

src/org/ibex/jinetd/Loader.java

index 8f9fef8..5a2b171 100644 (file)
@@ -1,4 +1,5 @@
 package org.ibex.jinetd;
 package org.ibex.jinetd;
+import org.ibex.io.*;
 import org.ibex.util.*;
 import java.io.*;
 import java.util.*;
 import org.ibex.util.*;
 import java.io.*;
 import java.util.*;
@@ -147,15 +148,36 @@ public class Loader extends Watcher {
                 path.endsWith(".jar") ) ? super.slash(path) : null; }
 
 
                 path.endsWith(".jar") ) ? super.slash(path) : null; }
 
 
+    private void nuke() {
+        if (tg.activeCount() == 0) return;
+        Log.info(this, "killing all threads for: " + path);
+        Log.info(this, "   thread count before interrupt: " + tg.activeCount());
+        tg.interrupt();
+        try { Thread.sleep(3000); } catch (Exception e) { Log.error(this, e); }
+        Log.info(this, "   thread count before kill: " + tg.activeCount());
+        Thread[] all = new Thread[tg.activeCount()];
+        tg.enumerate(all, true);
+        for(int i=0; i<all.length; i++) Stream.kill(all[i]);
+        try { Thread.sleep(3000); } catch (Exception e) { Log.error(this, e); }
+        Log.info(this, "   thread count after kill: " + tg.activeCount());
+        if (tg.activeCount() > 0) {
+            Log.warn(this, "    annoying threads:");
+            Thread[] annoying = new Thread[tg.activeCount()];
+            tg.enumerate(annoying, true);
+            for(int i=0; i<annoying.length; i++) {
+                Log.warn(this, "      " + annoying[i]);
+                StackTraceElement[] stack = annoying[i].getStackTrace();
+                for(int j=0; j<stack.length; j++) Log.warn(this, "        " + stack[j]);
+                Log.warn(this, " ");
+            }
+        }
+    }
+
     // dump the classloader if anything changes
     public void changed(Watched w) {
         if (w.path.indexOf("BIN") != -1) return;
         if (classloader != null) {
     // dump the classloader if anything changes
     public void changed(Watched w) {
         if (w.path.indexOf("BIN") != -1) return;
         if (classloader != null) {
-            Log.info(this, "killing all threads for: " + w.path);
-            Log.info(this, "   thread count before kill: " + tg.activeCount());
-            tg.interrupt();
-            try { Thread.sleep(1000); } catch (Exception e) { }
-            Log.info(this, "   thread count after kill: " + tg.activeCount());
+            for(int i=0; i<3; i++) nuke();
             tg = new ThreadGroup(getAbsolutePath());
             Log.info(this, "scheduling classes for reload due to change in: " + w.path);
             classloader = null;
             tg = new ThreadGroup(getAbsolutePath());
             Log.info(this, "scheduling classes for reload due to change in: " + w.path);
             classloader = null;