Hello,
We have SWT-based applet (uses SWT_AWT bridge) which we want to starts via webstart.
Problems occurs when we try start second instance of that applet (in same browser).
In last step of applet's UI initialization - on first call of display.readAndDispatch() is raised Invalid thread access exception.
Line 2 on following code ..
1. while (!shell.isDisposed()) {
2. if (!display.readAndDispatch()) {
3. display.sleep();
4. }
5. }
6. display.dispose();
Some facts:
- Each applet instance has own shell and display and runs in own threads.
- Same behavior in Mozilla Firefox and MS IE.
- Exception isn't raised when applet is started WITHOUT Webstart/JNLP (but in classic approach).
- Exception isn't raised when applet is started directly by javaws executable. I mean without browser java plugin (e.g. opening jnlp file from windows explorer). In that case have each applet own JVM.
- Usage of pack200 doesn't have any impact to this issue.
When applet is started by webstart from browser then all applets are running in same JVM but in different "sandboxes" (different classloaders?) - so it looks that applets are separated but there still remains some sharing in SWT internals.
Exception details:
Java Plug-in 1.6.0_21
Using JRE version 1.6.0_21-b07 Java HotSpot(TM) Client VM
..
..
Wed Oct 06 11:37:10 CEST 2010: TestApplet - Started
Wed Oct 06 11:37:10 CEST 2010: TestApplet - Initialized. Start UI Loop.
Exception in thread "UI" org.eclipse.swt.SWTException: Invalid thread access
at org.eclipse.swt.SWT.error(SWT.java:3884)
at org.eclipse.swt.SWT.error(SWT.java:3799)
at org.eclipse.swt.SWT.error(SWT.java:3770)
at org.eclipse.swt.widgets.Widget.error(Widget.java:463)
at org.eclipse.swt.widgets.Widget.checkWidget(Widget.java:355)
at org.eclipse.swt.widgets.Shell.getShell(Shell.java:1080)
at org.eclipse.swt.widgets.Control.sendFocusEvent(Control.java:2568)
at org.eclipse.swt.widgets.Widget.wmSetFocus(Widget.java:2282)
at org.eclipse.swt.widgets.Control.WM_SETFOCUS(Control.java:4573)
at org.eclipse.swt.widgets.Canvas.WM_SETFOCUS(Canvas.java:449)
at org.eclipse.swt.widgets.Decorations.WM_SETFOCUS(Decorations.java:1728)
at org.eclipse.swt.widgets.Control.windowProc(Control.java:4014)
at org.eclipse.swt.widgets.Canvas.windowProc(Canvas.java:342)
at org.eclipse.swt.widgets.Decorations.windowProc(Decorations.java:1578)
at org.eclipse.swt.widgets.Shell.windowProc(Shell.java:2010)
at org.eclipse.swt.widgets.Display.windowProc(Display.java:4589)
at org.eclipse.swt.internal.win32.OS.SetFocus(Native Method)
at org.eclipse.swt.widgets.Control.forceFocus(Control.java:978)
at org.eclipse.swt.widgets.Control.setFocus(Control.java:2965)
at org.eclipse.swt.widgets.Composite.setFocus(Composite.java:928)
at org.eclipse.swt.widgets.Shell.open(Shell.java:1220)
at example.TestApplet.run(TestApplet.java:65)
at java.lang.Thread.run(Unknown Source)
I can provide war archive with mentioned testing applet and JNLP files.
Thank in advance for any idea ..
Best regards