[libbluray-devel] BDJActionManager: add creator function
hpi1
git at videolan.org
Fri Mar 17 12:37:43 CET 2017
libbluray | branch: master | hpi1 <hpi1 at anonymous.org> | Thu Mar 16 14:57:06 2017 +0200| [9e5da9725e5901be4d9d241a86a72b87dd841db4] | committer: hpi1
BDJActionManager: add creator function
Avoid creating/starting thread in constructor of runnable class.
> http://git.videolan.org/gitweb.cgi/libbluray.git/?a=commit;h=9e5da9725e5901be4d9d241a86a72b87dd841db4
---
.../bdj/java/org/videolan/BDJActionManager.java | 2 +-
.../bdj/java/org/videolan/BDJActionQueue.java | 25 ++++++++++++++++------
src/libbluray/bdj/java/org/videolan/BDJLoader.java | 4 ++--
.../bdj/java/org/videolan/BDJXletContext.java | 6 +++---
.../java/org/videolan/media/content/BDHandler.java | 2 +-
5 files changed, 26 insertions(+), 13 deletions(-)
diff --git a/src/libbluray/bdj/java/org/videolan/BDJActionManager.java b/src/libbluray/bdj/java/org/videolan/BDJActionManager.java
index d8b46db..8168e60 100644
--- a/src/libbluray/bdj/java/org/videolan/BDJActionManager.java
+++ b/src/libbluray/bdj/java/org/videolan/BDJActionManager.java
@@ -32,7 +32,7 @@ public class BDJActionManager {
}
public BDJActionManager() {
- commandQueue = new BDJActionQueue("BDJActionManager");
+ commandQueue = BDJActionQueue.create("BDJActionManager");
}
protected static void shutdown() {
diff --git a/src/libbluray/bdj/java/org/videolan/BDJActionQueue.java b/src/libbluray/bdj/java/org/videolan/BDJActionQueue.java
index 1530c56..0e52432 100644
--- a/src/libbluray/bdj/java/org/videolan/BDJActionQueue.java
+++ b/src/libbluray/bdj/java/org/videolan/BDJActionQueue.java
@@ -21,23 +21,34 @@ package org.videolan;
import java.util.LinkedList;
public class BDJActionQueue implements Runnable {
- public BDJActionQueue(String name) {
- this(null, name);
+
+ public static BDJActionQueue create(String name) {
+ return create(null, name);
+ }
+
+ public static BDJActionQueue create(BDJThreadGroup threadGroup, String name) {
+ BDJActionQueue aq = new BDJActionQueue(threadGroup, name);
+ aq.startThread(threadGroup, name);
+ return aq;
}
- public BDJActionQueue(BDJThreadGroup threadGroup, String name) {
+ private BDJActionQueue(BDJThreadGroup threadGroup, String name) {
if (threadGroup == null) {
if (BDJXletContext.getCurrentContext() != null) {
- logger.error("BDJActionQueue created from wrong context: " + Logger.dumpStack());
+ logger.error("BDJActionQueue " + name + " created from wrong context: " + Logger.dumpStack());
+ // throw new SecurityException();
}
}
+ }
+ private void startThread(BDJThreadGroup threadGroup, String name) {
/* run all actions in given thread group / xlet context */
thread = new Thread(threadGroup, this, name + ".BDJActionQueue");
thread.setDaemon(true);
thread.start();
- watchdog = new Watchdog(name);
+ watchdog = new Watchdog();
+ watchdog.start(name);
}
public void shutdown() {
@@ -115,7 +126,9 @@ public class BDJActionQueue implements Runnable {
private Object currentAction = null;
private boolean terminate = false;
- Watchdog(String name) {
+ Watchdog() {}
+
+ synchronized void start(String name) {
Thread t = new Thread(null, this, name + ".BDJActionQueue.Monitor");
t.setDaemon(true);
t.start();
diff --git a/src/libbluray/bdj/java/org/videolan/BDJLoader.java b/src/libbluray/bdj/java/org/videolan/BDJLoader.java
index bbc150d..84cb0ae 100644
--- a/src/libbluray/bdj/java/org/videolan/BDJLoader.java
+++ b/src/libbluray/bdj/java/org/videolan/BDJLoader.java
@@ -136,7 +136,7 @@ public class BDJLoader {
return false;
synchronized (BDJLoader.class) {
if (queue == null)
- queue = new BDJActionQueue(null, "BDJLoader");
+ queue = BDJActionQueue.create("BDJLoader");
}
queue.put(new BDJLoaderAction(title, restart, callback));
return true;
@@ -147,7 +147,7 @@ public class BDJLoader {
synchronized (BDJLoader.class) {
if (queue == null)
- queue = new BDJActionQueue(null, "BDJLoader");
+ queue = BDJActionQueue.create("BDJLoader");
}
queue.put(new BDJLoaderAction(null, false, callback));
return true;
diff --git a/src/libbluray/bdj/java/org/videolan/BDJXletContext.java b/src/libbluray/bdj/java/org/videolan/BDJXletContext.java
index d076d1a..6a54abe 100644
--- a/src/libbluray/bdj/java/org/videolan/BDJXletContext.java
+++ b/src/libbluray/bdj/java/org/videolan/BDJXletContext.java
@@ -54,9 +54,9 @@ public class BDJXletContext implements javax.tv.xlet.XletContext, javax.microedi
entry.getInitialClass(),
this);
- callbackQueue = new BDJActionQueue(this.threadGroup, "CallbackQueue");
- mediaQueue = new BDJActionQueue(this.threadGroup, "MediaQueue");
- userEventQueue = new BDJActionQueue(this.threadGroup, "UserEventQueue");
+ callbackQueue = BDJActionQueue.create(this.threadGroup, "CallbackQueue");
+ mediaQueue = BDJActionQueue.create(this.threadGroup, "MediaQueue");
+ userEventQueue = BDJActionQueue.create(this.threadGroup, "UserEventQueue");
mountHomeDir(entry);
}
diff --git a/src/libbluray/bdj/java/org/videolan/media/content/BDHandler.java b/src/libbluray/bdj/java/org/videolan/media/content/BDHandler.java
index e3af4bb..fdd1c9b 100644
--- a/src/libbluray/bdj/java/org/videolan/media/content/BDHandler.java
+++ b/src/libbluray/bdj/java/org/videolan/media/content/BDHandler.java
@@ -79,7 +79,7 @@ public abstract class BDHandler implements Player, ServiceContentHandler {
}
private void doInitAction() {
- commandQueue = new BDJActionQueue("MediaPlayer");
+ commandQueue = BDJActionQueue.create("MediaPlayer");
PlayerManager.getInstance().registerPlayer(this);
}
More information about the libbluray-devel
mailing list