Skip to content

Commit ad2d5dd

Browse files
Executor improvements / Bus error logging (#164)
* Remove unnecessary check for Applet thread groups in thread factory. * Catch and log Throwables during Bus message dispatch.
1 parent 28aeb2f commit ad2d5dd

File tree

2 files changed

+10
-25
lines changed

2 files changed

+10
-25
lines changed

src/org/freedesktop/gstreamer/Bus.java

+8-3
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
import com.sun.jna.Pointer;
3636
import com.sun.jna.ptr.PointerByReference;
3737
import java.util.Locale;
38+
import java.util.logging.Level;
3839
import org.freedesktop.gstreamer.glib.Natives;
3940

4041
import org.freedesktop.gstreamer.lowlevel.GstAPI.GErrorStruct;
@@ -834,9 +835,13 @@ public synchronized <T> void disconnect(Class<T> listenerClass, T listener) {
834835
*/
835836
private void dispatchMessage(Message msg) {
836837
// Dispatch to listeners
837-
for (Object listener : messageProxies) {
838-
((MessageProxy) listener).busMessage(this, msg);
839-
}
838+
messageProxies.forEach((listener) -> {
839+
try {
840+
((MessageProxy) listener).busMessage(this, msg);
841+
} catch (Throwable t) {
842+
LOG.log(Level.SEVERE, "Exception thrown by bus message handler", t);
843+
}
844+
});
840845
}
841846

842847
private static class MessageProxy implements MESSAGE {

src/org/freedesktop/gstreamer/Gst.java

+2-22
Original file line numberDiff line numberDiff line change
@@ -630,30 +630,10 @@ public static boolean testVersion(int major, int minor) {
630630
private static final ThreadFactory threadFactory = new ThreadFactory() {
631631
private final AtomicInteger counter = new AtomicInteger(0);
632632

633-
/**
634-
* Determines if Gst has been started from an applet and returns it's
635-
* parent group.
636-
*
637-
* This is to avoid a problem where the service thread is killed when an
638-
* applet is destroyed. If multiple applets are active simultaneously,
639-
* this could be a problem.
640-
*
641-
* @return Applet's parent ("main") thread group or null, if not running
642-
* inside an applet
643-
*/
644-
private ThreadGroup getThreadGroup() {
645-
ThreadGroup tg = Thread.currentThread().getThreadGroup();
646-
try {
647-
Class<?> atgClass = Class.forName("sun.applet.AppletThreadGroup");
648-
return atgClass.isInstance(tg) ? tg.getParent() : null;
649-
} catch (ClassNotFoundException ex) {
650-
return null;
651-
}
652-
}
653-
633+
@Override
654634
public Thread newThread(Runnable task) {
655635
final String name = "gstreamer service thread " + counter.incrementAndGet();
656-
Thread t = new Thread(getThreadGroup(), task, name);
636+
Thread t = new Thread(task, name);
657637
t.setDaemon(true);
658638
t.setPriority(Thread.NORM_PRIORITY);
659639
return t;

0 commit comments

Comments
 (0)