From 9e436180285415c51427fbde82876efdc40882ed Mon Sep 17 00:00:00 2001
From: zzz <zzz@mail.i2p>
Date: Fri, 5 Dec 2014 15:35:38 +0000
Subject: [PATCH] Plugins: More thread group debugging for isRunning check;
 Don't count Jetty RolloverFileOutputStream in the thread group, to fix
 restart of a plugin

---
 .../src/net/i2p/router/web/PluginStarter.java | 23 ++++++++++++-------
 1 file changed, 15 insertions(+), 8 deletions(-)

diff --git a/apps/routerconsole/java/src/net/i2p/router/web/PluginStarter.java b/apps/routerconsole/java/src/net/i2p/router/web/PluginStarter.java
index 87780bcee4..edcaf2f980 100644
--- a/apps/routerconsole/java/src/net/i2p/router/web/PluginStarter.java
+++ b/apps/routerconsole/java/src/net/i2p/router/web/PluginStarter.java
@@ -843,9 +843,10 @@ public class PluginStarter implements Runnable {
             }
         }
 
+        boolean isClientThreadRunning = isClientThreadRunning(pluginName, ctx);
         if (log.shouldLog(Log.DEBUG))
-            log.debug("plugin name = <" + pluginName + ">; threads running? " + isClientThreadRunning(pluginName) + "; webapp runing? " + isWarRunning + "; jobs running? " + isJobRunning);
-        return isClientThreadRunning(pluginName) || isWarRunning || isJobRunning;
+            log.debug("plugin name = <" + pluginName + ">; threads running? " + isClientThreadRunning + "; webapp runing? " + isWarRunning + "; jobs running? " + isJobRunning);
+        return isClientThreadRunning || isWarRunning || isJobRunning;
         //
         //if (log.shouldLog(Log.DEBUG))
         //    log.debug("plugin name = <" + pluginName + ">; threads running? " + isClientThreadRunning(pluginName) + "; webapp runing? " + WebAppStarter.isWebAppRunning(pluginName) + "; jobs running? " + isJobRunning);
@@ -858,24 +859,30 @@ public class PluginStarter implements Runnable {
      * @param pluginName
      * @return true if running
      */
-    private static boolean isClientThreadRunning(String pluginName) {
+    private static boolean isClientThreadRunning(String pluginName, RouterContext ctx) {
         ThreadGroup group = pluginThreadGroups.get(pluginName);
         if (group == null)
             return false;
         boolean rv = group.activeCount() > 0;
         
-      /**** debugging to figure out active threads
+        // Plugins start before the eepsite, and will create the static Timer thread
+        // in RolloverFileOutputStream, which never stops. Don't count it.
         if (rv) {
-            Thread[] activeThreads = new Thread[32];
+            Log log = ctx.logManager().getLog(PluginStarter.class);
+            Thread[] activeThreads = new Thread[128];
             int count = group.enumerate(activeThreads);
+            boolean notRollover = false;
             for (int i = 0; i < count; i++) {
                 if (activeThreads[i] != null) {
-                    System.err.println("Found " + activeThreads[i].getState() + " thread for " +
-                                       pluginName + ": " + activeThreads[i].getName());
+                    String name = activeThreads[i].getName();
+                    if (!"org.eclipse.jetty.util.RolloverFileOutputStream".equals(name))
+                        notRollover = true;
+                    if (log.shouldLog(Log.DEBUG))
+                        log.debug("Found " + activeThreads[i].getState() + " thread for " + pluginName + ": " + name);
                 }
             }
+            rv = notRollover;
         }
-      ****/
 
         return rv;
     }
-- 
GitLab