libbluray | branch: master | hpi1 <[email protected]> | Thu Mar 27 14:35:48 2014 +0200| [c2f0675314247f1aa27c048dad409a394bc36fbe] | committer: hpi1
BDJ: Improve stopping Ixc threads > http://git.videolan.org/gitweb.cgi/libbluray.git/?a=commit;h=c2f0675314247f1aa27c048dad409a394bc36fbe --- .../bdj/java/org/videolan/BDJXletContext.java | 53 ++++++++++++++------ 1 file changed, 39 insertions(+), 14 deletions(-) diff --git a/src/libbluray/bdj/java/org/videolan/BDJXletContext.java b/src/libbluray/bdj/java/org/videolan/BDJXletContext.java index f49378d..e12e350 100644 --- a/src/libbluray/bdj/java/org/videolan/BDJXletContext.java +++ b/src/libbluray/bdj/java/org/videolan/BDJXletContext.java @@ -212,23 +212,48 @@ public class BDJXletContext implements javax.tv.xlet.XletContext, javax.microedi ixcThreads.remove(thread); } } + + private static boolean waitThread(Thread thread, int timeout) { + long startTime = System.currentTimeMillis(); + long endTime = startTime + timeout; + while (thread.isAlive() && (System.currentTimeMillis() < endTime)) { + try { + Thread.sleep(10); + } catch (InterruptedException e) { } + } + + boolean result = !thread.isAlive(); + if (!result) { + logger.error("waitThread timeout: " + thread); + } + return result; + } + + public static void stopThread(Thread thread, int timeout, String type) { + if (!waitForShutdown(thread, timeout)) { + thread.interrupt(); + if (!waitForShutdown(thread, 200)) { + PortingHelper.stopThread(thread); + logger.error("killing " + type + " thread " + t); + } + } + try { + thread.join(); + } catch (Throwable t) { } + } + 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); + while (true) { + Thread thread; + synchronized (ixcThreads) { + if (ixcThreads.isEmpty()) { + break; } + thread = (Thread)ixcThreads.removeFirst(); } + logger.info("Stopping remote thread " + thread); + stopThread(thread, 1000, "Ixc"); + removeIxcThread(thread); } } _______________________________________________ libbluray-devel mailing list [email protected] https://mailman.videolan.org/listinfo/libbluray-devel
