Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Alarming SwingUtilities.invokeLater Problem in OS 9



This is more of an FYI than specific help for this problem.

The InvokeLater function is intended for running quick UI related methods which should never be holding a lock when passed to InvokeLater. Since these are run during the event thread that updates all the UI components, doing otherwise will result in a poor user experience. There used to be a "long" list of component methods that could only be called as part of the event thread.

You may wish to have some utility thread(s) that can perform these functions instead of using InvokeLater.

You can use ctl break on Windows to force the JVM to print out the current stack of each thread. If threads are deadlocked, the JVM will indicate that and what they are deadlocked waiting for. On Unix you can use the kill command. The dump looks just like below in this mmessage.
http://java.sun.com/developer/onlineTraining/Programming/JDCBook/stack.html





At 1:39 PM -0600 8/15/05, Doug Zwick wrote:
We're now seeing a deadlock in our Swing application. We have recently made a change to do
more of our startup process on the Swing thread, so that Swing component updates will be
performed from the Swing thread. We do this using a Runnable passed in to
SwingUtilities.invokeLater. We wind up queuing a number of tasks. What is alarming is that
MRJ 2.2 seems to allow two of these runnables to execute at once, from different threads,
which leads to the deadlock we are seeing.


The two threads are:

"AWT-Dispatch-Proxy"
TID: $49945f20, prio: 5
sys_thread: $4682b864, priority: 5, saved_sp: $46e8de7c
state: WMON, mon: $46930260, cq: $491c04fc
$482edaf0 -> com.elluminate.vclass.client.VClass.setModuleDisplayAnnotation(VClass.java:3801)
$4915a268 -> com.elluminate.groupware.whiteboard.module.WhiteboardBean.displayTitleText(WhiteboardBean.java:1424)
$49fe6d68 -> com.elluminate.groupware.whiteboard.module.ui.ControllerPane$9.run(ControllerPane.java:1174)
$48232370 -> com.elluminate.util.Debug$SwingDebugWrapper.run(Compiled Code)
$48232370 -> javax.swing.SystemEventQueueUtilities.processRunnableEvent(Compiled Code)
$48232370 -> javax.swing.SystemEventQueueUtilities$RunnableTarget.processEvent(Compiled Code)
$48232370 -> java.awt.Component.dispatchEventImpl(Compiled Code)
$48232370 -> java.awt.Component.dispatchEvent(Compiled Code)
$49945f20 -> java.awt.EventDispatchThread.run(EventDispatchThread.java)


and

"AWT-EventQueue-0"
TID: $481561d0, prio: 5
sys_thread: $491c04fc, priority: 5, saved_sp: $480a06a4
state: WCV, mon: $4922d0fc, cq: $4922d108
$45c03a20 -> java.lang.Object.wait(Compiled Code)
$45c03a20 -> com.apple.mrj.internal.awt.VFramePeer.setVisible(VFramePeer.java)
$45c03a20 -> com.apple.mrj.internal.awt.VComponentPeer.show(VComponentPeer.java)
$45c03168 -> java.awt.Dialog.show(Dialog.java)
$49d3c928 -> com.elluminate.util.ModalDialog$2.run(Compiled Code)
$49d3c928 -> com.elluminate.util.ModalDialog$QueuedRequest.queueRequest(Compiled Code)
$49d3c928 -> com.elluminate.util.ModalDialog$QueuedRequest.queueRequest(ModalDialog.java:998)
$0 -> com.elluminate.util.ModalDialog.showInputDialogTimeout(ModalDialog.java:665)
$482edaf0 -> com.elluminate.util.ModalDialog.showInputDialog(ModalDialog.java:398)
$483ae640 -> com.elluminate.groupware.online.module.OnlineModule.join(OnlineModule.java:718)
$483ae640 -> com.elluminate.groupware.online.module.OnlineModule.start(OnlineModule.java:1113)
$48232370 -> com.elluminate.vclass.client.VClass$22.run(Compiled Code)
$48232370 -> com.elluminate.util.Debug$SwingDebugWrapper.run(Compiled Code)
$48232370 -> javax.swing.SystemEventQueueUtilities.processRunnableEvent(Compiled Code)
$48232370 -> javax.swing.SystemEventQueueUtilities$RunnableTarget.processEvent(Compiled Code)
$48232370 -> java.awt.Component.dispatchEventImpl(Compiled Code)
$48232370 -> java.awt.Component.dispatchEvent(Compiled Code)
$481561d0 -> java.awt.EventDispatchThread.run(EventDispatchThread.java)


The Runnable being run by AWT-EventQueue-0 is started first. It gets and holds the monitor that
the second Runnable (being run by AWT-Dispatch-Proxy) is waiting for. AWT-EventQueue-0 is in the
process of posting a modal dialog. When the dialog is showing I would expect to see a nested AWT
event loop on the stack of AWT-EventQueue-0, that in turn would process Runnables queued using
SwingUtilities.invokeLater.


I suspect that VFramePeer is depending on AWT-Dispatch-Proxy to make the peer visible, but it
can't because it is blocked waiting for the monitor. If the one being run by AWT-Dispatch-Proxy
had been run from AWT-EventQueue-0, there would be no deadlock (although the assumptions of the
calling thread that no other thread-of-execution will be able to muck with the object locked by
the held monitor may well be invalidated).


Can anyone shed any light on what the "AWT-Dispatch-Proxy" thread is supposed to be doing, and
why it is servicing the main event queue? Could this be a feature of the AWT event loop to keep
logically distinct threads-of-execution that may be executing on the same Thread from munging
data under a locked monitor?
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Java-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/java-dev/email@hidden


This email sent to email@hidden

_______________________________________________ Do not post admin requests to the list. They will be ignored. Java-dev mailing list (email@hidden) Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/java-dev/email@hidden

This email sent to email@hidden
References: 
 >Alarming SwingUtilities.invokeLater Problem in OS 9 (From: Doug Zwick <email@hidden>)



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.