From c5bec6b8f5c33a812338dcbe8994546bddf0508b Mon Sep 17 00:00:00 2001 From: Sven Gothel Date: Sun, 22 Sep 2013 02:35:11 +0200 Subject: Fix Bug 840: DefaultEDTUtil.restart() shall only reuse ThreadGroup (tg) is not destroyed, otherwise use current thread's tg. With jdk7u40, when re-launching a NEWT applet (JOGLNewtApplet1Run), i.e. via browser back and forth, the following exception happens: java.lang.RuntimeException: java.lang.IllegalThreadStateException at com.jogamp.newt.awt.applet.JOGLNewtApplet1Run.init(JOGLNewtApplet1Run.java:218) at com.sun.deploy.uitoolkit.impl.awt.AWTAppletAdapter.init(Unknown Source) at sun.plugin2.applet.Plugin2Manager$AppletExecutionRunnable.run(Unknown Source) at java.lang.Thread.run(Unknown Source) Caused by: java.lang.IllegalThreadStateException at java.lang.ThreadGroup.addUnstarted(Unknown Source) at java.lang.Thread.init(Unknown Source) at java.lang.Thread.(Unknown Source) at jogamp.newt.DefaultEDTUtil$NEDT.(DefaultEDTUtil.java:280) at jogamp.newt.DefaultEDTUtil.restart(DefaultEDTUtil.java:91) at jogamp.newt.DisplayImpl.runOnEDTIfAvail(DisplayImpl.java:231) at jogamp.newt.WindowImpl.runOnEDTIfAvail(WindowImpl.java:1758) at jogamp.newt.WindowImpl.setUndecorated(WindowImpl.java:1477) at com.jogamp.newt.opengl.GLWindow.setUndecorated(GLWindow.java:278) at com.jogamp.newt.awt.applet.JOGLNewtApplet1Run.init(JOGLNewtApplet1Run.java:188) ... 3 more This is due to 7u40's changed ThreadGroup (tg) lifecycle, i.e. the tg is destroyed. In such case, DefaultEDTUtil.restart() shall use the current threads tg. --- src/newt/classes/jogamp/newt/DefaultEDTUtil.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/newt/classes/jogamp/newt/DefaultEDTUtil.java b/src/newt/classes/jogamp/newt/DefaultEDTUtil.java index a229a0512..5794d4ae9 100644 --- a/src/newt/classes/jogamp/newt/DefaultEDTUtil.java +++ b/src/newt/classes/jogamp/newt/DefaultEDTUtil.java @@ -38,6 +38,7 @@ package jogamp.newt; import java.util.ArrayList; + import javax.media.nativewindow.NativeWindowException; import jogamp.common.util.locks.LockDebugUtil; @@ -50,7 +51,7 @@ public class DefaultEDTUtil implements EDTUtil { public static final boolean DEBUG = Debug.debug("EDT"); private final Object edtLock = new Object(); // locking the EDT start/stop state - private final ThreadGroup threadGroup; + private /* final */ ThreadGroup threadGroup; private final String name; private final Runnable dispatchMessages; private NEDT edt = null; @@ -88,6 +89,10 @@ public class DefaultEDTUtil implements EDTUtil { System.err.println(Thread.currentThread()+": Default-EDT reset - edt: "+edt); } if( edt.getState() != Thread.State.NEW ) { + if( null != threadGroup && threadGroup.isDestroyed() ) { + // best thing we can do is to use this thread's TG + threadGroup = Thread.currentThread().getThreadGroup(); + } edt = new NEDT(threadGroup, name); edt.setDaemon(true); // don't stop JVM from shutdown .. } -- cgit v1.2.3