AppContext issue in Apple Java 6 -- same issue in Oracle Java 7?

Doug Zwick Doug.Zwick at blackboard.com
Mon Jul 8 08:52:54 PDT 2013


Andrew Thompson wrote:

> But I can deploy trusted code by signing an applet or a webstart application and it can create a Thread in another ThreadGroup. Elsewhere in this thread people mention JNI and RMI threads and Cocoa's main thread. This is all valid code; there's no prohibitions against doing any of these things.

It may be that the ideal thing for Java to do in this situation is to have the Thread inherit the AppContext of its creator thread, rather than that of the ThreadGroup specified in the Thread c'tor. That may not be practical. Perhaps throwing an Exception in such a circumstance would be reasonable, or even just a warning message on System.err.

> I understand it is intended that this AppContext idea is transparent and ideally it would be. But at the present time it appears that the abstraction leaks [1] and there is no workarounds possible using supported code (rather than sun.* classes). Have I misunderstood something in this thread?

The work-around I came up with was to create my own Thread, in the right context, that services a queue of Runnables. Then code running on the AppKit Thread, an RMI Thread, etc. can queue a Runnable to be run on that Thread (similar to SwingUtilities.invokeLater). It gets cumbersome to defer things to the Swing thread from such a "bad" context, as you need to queue a Runnable to the work-around Thread that then queues yet another Runnable for the Swing Thread. But it does work. I do not know if invoke-and-wait semantics would be reasonable, as blocking the AppKit Thread can lead to trouble (i.e. deadlocks), but may be OK in the RMI case.


This email and any attachments may contain confidential and proprietary information of Blackboard that is for the sole use of the intended recipient. If you are not the intended recipient, disclosure, copying, re-distribution or other use of any of this information is strictly prohibited. Please immediately notify the sender and delete this transmission if you received this email in error.


More information about the macosx-port-dev mailing list