Web Start: Invalid thread access with SWT APPS in MAC
I m getting an invalid thread access error when starting my app with Mac OS X. It works fine under windows and Linux. That s what makes me think it s a SWT Mac OS X bug... Attached is a screenshot of the error /app .
Created attachment 10916[details]
Mac OS X invalid thread access
I know this bug is going to be difficult to fix with only that info. But such a
general error makes me think : 1) either I miss something 2) or we are in big
trouble :)
My app is started directly from Java Web Start, from the browser.
I also started it directly command line under mac os X, with Java\ Web\ Start .
In both cases I have the same exceptions.
Java web start not supported ? This is weird.
1) many articles from IBM show how to use JWS & SWT. And it works like a charm
under Linux & Windows.
2) I don t think there is a need for JWS support. Everything Java is supposed to
run with JWS, and I m very confident on that point. If SWT does not support JWS,
it looks like SWT does not support Java somewhere.
I d like more clarifications on that point.... should it be the answer of that bug.
I was able to run the application from command Line instead of Java web start,
at my surprise.
I am used to run JWS & SWT under windows & linux. Is there any specific reason
why it does not work with Mac. ? Shall we take the windows & linux
compatibility as a lucky fact ?
Andre,
You know more about this problem than me. Please could you explain why we need
the java_swt executable? For a short answer, we need to run main() in the
carbon UI thread.
You find the full story why we need java_swt in comment 3 of bug #40003.
> I was able to run the application from command Line instead of Java web start,
at my surprise.
In MacOS X? If yes, what exactly did you do?
Yes under Mac OS X. I just run from command line using java , not java_swt.
So it appears to be a well known 'bug' of javaswt / mac OS X. I think we can
close this bug, unless you have other comments.
yes it does. This is the app described above, which when launched from javaws
gives the invalid thread access. When run from command line, it works fine.
Both tries under mac OS X.
I've debugged webstart with SWT on MacOS X and here is the result:
- the attribute java-vm-args="-XstartOnFirstThread" doesn't have an effect.
As a consequence the Java VM runs in the wrong thread and SWT apps appear,
but don't react to user input.
- I replaced /usr/bin/java with a shell script that passes a -XstartOnFirstThread
to the original java VM. In this case webstarts aborts because it tries to launch AWT which fails
because it runs in the wrong thread. This scenario shows that even if
java-vm-args="- XstartOnFirstThread" would be passed to the VM,
running SWT would still not work.
This Catch-22 can only be solved by either fixing the SWT/AWT interoperability issues,
or by running a fresh Java VM for the application being launched via webstart (so that AWT and SWT
are not used within the same Java VM).
Todd, is there anything we can do on the Mac to have JWS start on the *right*
thread?
NOTE: If JWS uses AWT, then this is bug is another instance of bug 67384 and
can possibly be closed as a dup. When multiple operating system GUI threads
work in the same process on a Mac, then JWS should work the same way it does
on Windows and Linux.
This will need some work on our part. I can make -XstartOnFirstThread a 'safe' VM option, so that it gets passed to the JVM, but the problem is that a lot of AWT code is executed long before the SWT's event loop starts. My current thinking is that we need the runloop running on thread 0, much like we do in the AWT.
Another possibility is to start up the AWT as we do now, but when the actual application is about to launch, shut down the NSApplication and let the SWT event handling take over.
Completely unrelated. 145890 involves embedding an SWT shell into an AWT window. This bug deals with the fact that Web Start on Mac OS X is starting up in such a way that the SWT cannot be used.
Nothing new to report right now. We have some core problems with SWT and AWT running together that I need to address first. Once that happens I can look at having the SWT start after the AWT which is the root problem here.
We've been running 1.5 since the summer, and this bug still exists. 1.6 is the latest 'stable' version... I haven't seen if 1.6 fixes the issue yet or not since we are holding off from upgrading.
Checked this in last night for our Java 1.5 in Leopard. To use this, you will need to let the JVM know you're going to use the SWT:
<resources os="Mac OS X">
<j2se version="1.5*" java-vm-args="-XstartOnFirstThread"/>
<jar href="SWTWebStart.jar"/>
</resources>
I will move to resolved/fixed when a public build with this fix is available.
Ok, so let me understand this (correct me if I'm wrong here): the next public build for Java 1.5/1.6 on Leopard will contain this fix and when it's out there, we just need the reference to the SWTWebStart.jar in the JNLP?
Sorry, my previous comment wasn't clear:
<resources os="Mac OS X">
....
<j2se version="1.5*" java-vm-args="-XstartOnFirstThread"/>
....
</resources>
The 'java-vm-args="-XstartOnFirstThread"' is the important part. The next public build of Leopard 1.5 will have this support, which is why I wrote the resources section this way. The JAR file was from a local test, and not relevant here.
I still need to merge it into 1.6, but I'm also not commenting when that will be released. I'll update here when that happens.
(In reply to comment #36)
> Sorry, my previous comment wasn't clear:
>
> <resources os="Mac OS X">
> ....
> <j2se version="1.5*" java-vm-args="-XstartOnFirstThread"/>
> ....
> </resources>
>
> The 'java-vm-args="-XstartOnFirstThread"' is the important part. The next
> public build of Leopard 1.5 will have this support, which is why I wrote the
> resources section this way. The JAR file was from a local test, and not
> relevant here.
>
> I still need to merge it into 1.6, but I'm also not commenting when that will
> be released. I'll update here when that happens.
Does your fix works also with others java graphical toolkits that need "-XstartOnFirstThread" JVM argument on start like QtJambi ?
Thread about the issue between JWS and Jambi under OSX:
http://lists.trolltech.com/qt-jambi-interest/2007-03/thread00073-0.html
How build native QtJambi jar for Mac OS X:
http://lists.trolltech.com/qt-jambi-interest/2007-06/thread00003-0.html
Does QT-Jambi run its own event loop like the SWT does? Looking at QApplication's javadoc page, it looks like it does, so then, yes, this change is probably useful for QTJambi as well.
(In reply to comment #42)
> I noticed this bug is marked as fixed so does that close the book for Tiger
> compatibility? :(
I can't recall right now if we back-ported this into the last Tiger update released at the end of 2007. I have this vague recollection that I did, but I'm not sure now.
I no longer work for Apple, but please file a bug at bugreport.apple.com to remind someone that this can and should go back into Tiger.
Shouldn't this issue have a target milestone? That is usually the field used for reporting when an issue was fixed, whereas the Version field describes what version it was reported against.
This was fixed in the released Mac OS X 10.5 (see comment #41) -- no additional updates needed. I'm changing the resolution to NOT_ECLIPSE since it was a Mac JVM fix that took care of it.
I'm almost certain it was not back-ported to 10.4, since it's not security-related.
(In reply to comment #49)
> Please update http://www.eclipse.org/swt/jws/ noting that this bug no longer
> applies with recent Mac OS X versions.
Good catch -- the comment at the bottom of that page is indeed no longer valid.
I believe Carolyn owns the web pages, so I'll ask her to update it.
Please reopen this bug because of Mac OS X 10.6.6 this bug exists.
I think, javaws ignores parameter -XstartOnFirstThread. This problem only occurs on launching application with Java Webstart.
Starting on shell only with java and parameter -XstartOnFirstThread does well.
Without this parameter, the same error occurs.
javaws -J-XstartOnFirstThread
doesn't work, too.
(In reply to comment #53)
> Do you guys know anything about -XstartOnFirstThread being broken for web start
> with 10.6.6 ?
I do not believe we have changed the -XstartOnFirstThread code path at all in any of the Java updates for Mac OS X 10.6.
If you have specific steps to reproduce, I would suggest that you file a new bug.
I just tried the latest SWT code on 10.6.7 and found this bug#342488 which was caused by the changes released for bug#329456 on March 3th, 2011 (which is after the date of comment#52).
Other than bug#342488 everything seems to be working fine. I do not get an Invalid
thread access exception if the jnlp file specifies -XstartOnFirstThread properly.
Heiko Roth, please try the test case attached to bug#342488 (note that you need to update the path in the jnlp file) and let me know if it works for you. I do not think this bug is back.
(In reply to comment #55)
> Other than bug#342488 everything seems to be working fine. I do not get an
> Invalid
> thread access exception if the jnlp file specifies -XstartOnFirstThread
> properly.
>
> Heiko Roth, please try the test case attached to bug#342488 (note that you need
> to update the path in the jnlp file) and let me know if it works for you. I do
> not think this bug is back.
Thank you for the example in bug#342488. It worked out of the box.
We found the problem inside our jnlp file.
<resources>
<!-- REMOVED <j2se version="1.6+" /> REMOVED -->
<!-- Application Resources -->
<jar href="javaclient-3796.jar" main="true" />
<jar href="lib/apache-mime4j-0.6.jar" />
<jar href="lib/commons-codec-1.3.jar" />
<jar href="lib/commons-httpclient-3.1.jar" />
<jar href="lib/commons-logging-1.1.1.jar" />
<jar href="lib/json_simple-1.1.jar" />
</resources>
<resources os="Mac OS X" arch="x86_64">
<j2se version="1.6+" java-vm-args="-XstartOnFirstThread" />
<jar href="lib/swt-macosx.jar" />
</resources>
We removed the first <j2se version="1.6+" /> entry and everything worked fine.
Thanks.
Web Start: Invalid thread access
Web Start: Invalid thread access with SWT APPS in MAC