[libbluray-devel] Do not create+start thread in constructor
hpi1
git at videolan.org
Mon Nov 17 13:09:44 CET 2014
libbluray | branch: master | hpi1 <hpi1 at anonymous.org> | Mon Nov 17 10:55:23 2014 +0200| [b37f897b7b17aa1aba0443b6785f4dbed4200a58] | committer: hpi1
Do not create+start thread in constructor
> http://git.videolan.org/gitweb.cgi/libbluray.git/?a=commit;h=b37f897b7b17aa1aba0443b6785f4dbed4200a58
---
src/libbluray/bdj/java/org/videolan/BDJAppProxy.java | 17 ++++++++++++++---
src/libbluray/bdj/java/org/videolan/BDJLoader.java | 2 +-
2 files changed, 15 insertions(+), 4 deletions(-)
diff --git a/src/libbluray/bdj/java/org/videolan/BDJAppProxy.java b/src/libbluray/bdj/java/org/videolan/BDJAppProxy.java
index ccefb8a..623c829 100644
--- a/src/libbluray/bdj/java/org/videolan/BDJAppProxy.java
+++ b/src/libbluray/bdj/java/org/videolan/BDJAppProxy.java
@@ -30,9 +30,15 @@ import java.util.LinkedList;
import javax.tv.xlet.Xlet;
public class BDJAppProxy implements DVBJProxy, Runnable {
- public BDJAppProxy(BDJXletContext context) {
- this.context = context;
- state = NOT_LOADED;
+ protected static BDJAppProxy newInstance(BDJXletContext context) {
+ BDJAppProxy proxy = new BDJAppProxy(context);
+ /* do not create and start thread in constructor.
+ if constructor fails (exception), thread is left running without BDJAppProxy ... */
+ proxy.startThread();
+ return proxy;
+ }
+
+ private void startThread() {
thread = new Thread(context.getThreadGroup(), this, "BDJAppProxy");
thread.setDaemon(true);
thread.start();
@@ -46,6 +52,11 @@ public class BDJAppProxy implements DVBJProxy, Runnable {
}
}
+ private BDJAppProxy(BDJXletContext context) {
+ this.context = context;
+ state = NOT_LOADED;
+ }
+
public int getState() {
return state;
}
diff --git a/src/libbluray/bdj/java/org/videolan/BDJLoader.java b/src/libbluray/bdj/java/org/videolan/BDJLoader.java
index 87f749e..1b59dcd 100644
--- a/src/libbluray/bdj/java/org/videolan/BDJLoader.java
+++ b/src/libbluray/bdj/java/org/videolan/BDJLoader.java
@@ -171,7 +171,7 @@ public class BDJLoader {
// initialize appProxys
for (int i = 0; i < appTable.length; i++) {
if (proxys[i] == null) {
- proxys[i] = new BDJAppProxy(
+ proxys[i] = BDJAppProxy.newInstance(
new BDJXletContext(
appTable[i],
bdjo.getAppCaches(),
More information about the libbluray-devel
mailing list