[libbluray-devel] Try to stop all xlet threads when context is released

hpi1 git at videolan.org
Sun Apr 14 15:08:59 CEST 2013


libbluray | branch: master | hpi1 <hpi1 at anonymous.org> | Fri Apr 12 11:23:50 2013 +0300| [b88762ab187ff4f20b8cd2272dcfd039c82b7fae] | committer: hpi1

Try to stop all xlet threads when context is released

> http://git.videolan.org/gitweb.cgi/libbluray.git/?a=commit;h=b88762ab187ff4f20b8cd2272dcfd039c82b7fae
---

 .../bdj/java/org/videolan/BDJThreadGroup.java      |   38 +++++++++++++++++++-
 .../bdj/java/org/videolan/BDJXletContext.java      |    4 +++
 2 files changed, 41 insertions(+), 1 deletion(-)

diff --git a/src/libbluray/bdj/java/org/videolan/BDJThreadGroup.java b/src/libbluray/bdj/java/org/videolan/BDJThreadGroup.java
index 2863135..c644ad2 100644
--- a/src/libbluray/bdj/java/org/videolan/BDJThreadGroup.java
+++ b/src/libbluray/bdj/java/org/videolan/BDJThreadGroup.java
@@ -47,10 +47,46 @@ public class BDJThreadGroup extends ThreadGroup {
 
         boolean result = (activeCount() <= maxThreads);
         if (!result) {
-            Logger.getLogger("BDJThreadGroup").error("waitForShutdown timeout");
+            logger.error("waitForShutdown timeout");
         }
         return result;
     }
 
+    protected void stopAll(int timeout) {
+
+        interrupt();
+        waitForShutdown(0, timeout);
+
+        if (activeCount() > 0) {
+            logger.error("stopAll(): killing threads");
+            dumpThreads();
+
+            PortingHelper.stopThreadGroup(this);
+            waitForShutdown(0, 500);
+        }
+
+        try {
+            destroy();
+        } catch (IllegalThreadStateException e) {
+            logger.error("ThreadGroup destroy failed: " + e);
+        }
+
+        context = null;
+    }
+
+    public void dumpThreads() {
+        logger.info("Active threads in " + this + ":");
+        Thread[] threads = new Thread[activeCount() + 1];
+        while (enumerate( threads, true ) == threads.length) {
+            threads = new Thread[threads.length * 2];
+        }
+        for (int i = 0; i < threads.length; i++) {
+            if (threads[i] == null)
+                continue;
+            logger.info("    " + threads[i]);
+        }
+    }
+
     private BDJXletContext context;
+    private static final Logger logger = Logger.getLogger(BDJThreadGroup.class.getName());
 }
diff --git a/src/libbluray/bdj/java/org/videolan/BDJXletContext.java b/src/libbluray/bdj/java/org/videolan/BDJXletContext.java
index bda49c1..ed034a9 100644
--- a/src/libbluray/bdj/java/org/videolan/BDJXletContext.java
+++ b/src/libbluray/bdj/java/org/videolan/BDJXletContext.java
@@ -166,6 +166,10 @@ public class BDJXletContext implements javax.tv.xlet.XletContext, javax.microedi
             java.awt.BDJHelper.stopEventQueue(eq);
         }
 
+        threadGroup.stopAll(1000);
+
+        threadGroup = null;
+        loader = null;
         container = null;
     }
 



More information about the libbluray-devel mailing list