libbluray | branch: master | hpi1 <[email protected]> | Wed May 8 13:11:12 2013 +0300| [241f5faceb5632ccb19508d073482e917a9ab806] | committer: hpi1
Stop remote (Ixc) threads when stopping xlet. Remote threads run in callee context / thread group. > http://git.videolan.org/gitweb.cgi/libbluray.git/?a=commit;h=241f5faceb5632ccb19508d073482e917a9ab806 --- .../bdj/java/org/videolan/BDJXletContext.java | 33 ++++++++++++++++++++ .../bdj/java/org/videolan/IxcRegistryImpl.java | 4 +-- 2 files changed, 35 insertions(+), 2 deletions(-) diff --git a/src/libbluray/bdj/java/org/videolan/BDJXletContext.java b/src/libbluray/bdj/java/org/videolan/BDJXletContext.java index 33e10b1..bccf7fb 100644 --- a/src/libbluray/bdj/java/org/videolan/BDJXletContext.java +++ b/src/libbluray/bdj/java/org/videolan/BDJXletContext.java @@ -21,6 +21,7 @@ package org.videolan; import java.awt.Container; import java.awt.EventQueue; +import java.util.LinkedList; import java.security.AccessController; import java.security.PrivilegedAction; @@ -132,6 +133,35 @@ public class BDJXletContext implements javax.tv.xlet.XletContext, javax.microedi return sceneFactory; } + protected void addIxcThread(Thread thread) { + synchronized (ixcThreads) { + ixcThreads.addLast(thread); + } + } + protected void removeIxcThread(Thread thread) { + synchronized (ixcThreads) { + ixcThreads.remove(thread); + } + } + protected void stopIxcThreads() { + synchronized (ixcThreads) { + while (!ixcThreads.isEmpty()) { + Thread thread = (Thread)ixcThreads.removeFirst(); + logger.info("Stopping remote thread " + thread); + thread.interrupt(); + try { + thread.join(500); + } catch (Throwable t) { + } + if (thread.isAlive()) { + PortingHelper.stopThread(thread); + } + if (thread.isAlive()) { + logger.error("Error stopping remote thread " + thread); + } + } + } + } public static BDJXletContext getCurrentContext() { Object obj = AccessController.doPrivileged( @@ -163,6 +193,8 @@ public class BDJXletContext implements javax.tv.xlet.XletContext, javax.microedi } protected void release() { + stopIxcThreads(); + if (sceneFactory != null) { sceneFactory.dispose(); sceneFactory = null; @@ -188,5 +220,6 @@ public class BDJXletContext implements javax.tv.xlet.XletContext, javax.microedi private EventQueue eventQueue = null; private HSceneFactory sceneFactory = null; private BDJThreadGroup threadGroup = null; + private LinkedList ixcThreads = new LinkedList(); private static final Logger logger = Logger.getLogger(BDJXletContext.class.getName()); } diff --git a/src/libbluray/bdj/java/org/videolan/IxcRegistryImpl.java b/src/libbluray/bdj/java/org/videolan/IxcRegistryImpl.java index 5436035..10f0d9c 100644 --- a/src/libbluray/bdj/java/org/videolan/IxcRegistryImpl.java +++ b/src/libbluray/bdj/java/org/videolan/IxcRegistryImpl.java @@ -168,11 +168,11 @@ public class IxcRegistryImpl { Thread remoteThread = new Thread(remoteObj.context.getThreadGroup(), remoteMethod, "Ixc Remote thread " + method); - /* TODO: track threads so that unfinished threads can be killed when Xlet is terminated */ - + remoteMethod.callerContext.addIxcThread(remoteThread); remoteThread.setDaemon(false); remoteThread.start(); remoteThread.join(); + remoteMethod.callerContext.removeIxcThread(remoteThread); if (!remoteMethod.finished) { throw new RemoteException("calling xlet destroyed during remote execution"); _______________________________________________ libbluray-devel mailing list [email protected] http://mailman.videolan.org/listinfo/libbluray-devel
