libbluray | branch: master | hpi1 <[email protected]> | Fri Apr 12 10:43:22 2013 +0300| [c83c092c25a5e0bfd09e960f9505e8ddfd34c9c2] | committer: hpi1
Improve BDJAppProxy shutdown: do not wait for event queue threads > http://git.videolan.org/gitweb.cgi/libbluray.git/?a=commit;h=c83c092c25a5e0bfd09e960f9505e8ddfd34c9c2 --- src/libbluray/bdj/java/org/videolan/BDJAppProxy.java | 5 +++-- .../bdj/java/org/videolan/BDJThreadGroup.java | 18 ++++++++++++++++++ .../bdj/java/org/videolan/BDJXletContext.java | 12 ++++++++++++ 3 files changed, 33 insertions(+), 2 deletions(-) diff --git a/src/libbluray/bdj/java/org/videolan/BDJAppProxy.java b/src/libbluray/bdj/java/org/videolan/BDJAppProxy.java index 3ca8a6c..9829223 100644 --- a/src/libbluray/bdj/java/org/videolan/BDJAppProxy.java +++ b/src/libbluray/bdj/java/org/videolan/BDJAppProxy.java @@ -234,8 +234,9 @@ public class BDJAppProxy implements DVBJProxy, Runnable { if ((state != NOT_LOADED) && (state != LOADED)) { try { xlet.destroyXlet(force); - for (int i = 0; (i < 50) && (context.getThreadGroup().activeCount() > 1); i++) - Thread.sleep(20L); + + context.getThreadGroup().waitForShutdown(1000, 1 + context.numEventQueueThreads()); + String persistent = System.getProperty("dvb.persistent.root") + File.separator + (String)context.getXletProperty("dvb.org.id") + File.separator + (String)context.getXletProperty("dvb.app.id"); diff --git a/src/libbluray/bdj/java/org/videolan/BDJThreadGroup.java b/src/libbluray/bdj/java/org/videolan/BDJThreadGroup.java index 17a0f90..2863135 100644 --- a/src/libbluray/bdj/java/org/videolan/BDJThreadGroup.java +++ b/src/libbluray/bdj/java/org/videolan/BDJThreadGroup.java @@ -1,6 +1,7 @@ /* * This file is part of libbluray * Copyright (C) 2010 William Hahne + * Copyright (C) 2013 Petri Hintukainen <[email protected]> * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -34,5 +35,22 @@ public class BDJThreadGroup extends ThreadGroup { this.context = context; } + public boolean waitForShutdown(int maxThreads, int timeout) { + long startTime = System.currentTimeMillis(); + long endTime = startTime + 1000; + while ((activeCount() > maxThreads) && + (System.currentTimeMillis() < endTime)) { + try { + Thread.sleep(10); + } catch (InterruptedException e) { } + } + + boolean result = (activeCount() <= maxThreads); + if (!result) { + Logger.getLogger("BDJThreadGroup").error("waitForShutdown timeout"); + } + return result; + } + private BDJXletContext context; } diff --git a/src/libbluray/bdj/java/org/videolan/BDJXletContext.java b/src/libbluray/bdj/java/org/videolan/BDJXletContext.java index da98998..718dc3a 100644 --- a/src/libbluray/bdj/java/org/videolan/BDJXletContext.java +++ b/src/libbluray/bdj/java/org/videolan/BDJXletContext.java @@ -1,6 +1,7 @@ /* * This file is part of libbluray * Copyright (C) 2010 William Hahne + * Copyright (C) 2013 Petri Hintukainen <[email protected]> * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -100,6 +101,17 @@ public class BDJXletContext implements javax.tv.xlet.XletContext, javax.microedi return eventQueue; } + protected int numEventQueueThreads() { + int cnt = 0; + if (eventQueue != null) { + Thread t = java.awt.BDJHelper.getEventDispatchThread(eventQueue); + if (t != null && t.isAlive()) { + cnt++; + } + } + return cnt; + } + public void setSceneFactory(HSceneFactory f) { sceneFactory = f; } _______________________________________________ libbluray-devel mailing list [email protected] http://mailman.videolan.org/listinfo/libbluray-devel
