dcsimg
Problem executing on the EventDispatch Thread in a an applet.
0 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Mark_Schmeets
Posted On:   Friday, April 26, 2002 12:51 PM

I have an applet ( one of three on a page -- but the others don't matter here ) that has a static member variable, a class derived from JFrame. There is some JavaScript on the page which calls a method on the applet ( in response to an onClick event ), the applet passes this call through to the frame, which in turn displays data based on the id it receives through these events. The problem is strange and unpredictable behavior which I have traced down to a problem with multiple threads accessing the Swing GUI. So I tried to use the SwingUtilities.invokeLater to ensure that the calls were occurring on the Event Dispatch thread. Still have strange and unpredictable behavior.... Below is an excerpt of the thread dump:    More>>

I have an applet ( one of three on a page -- but the others don't matter here ) that has a static member variable, a class derived from JFrame. There is some JavaScript on the page which calls a method on the applet ( in response to an onClick event ), the applet passes this call through to the frame, which in turn displays data based on the id it receives through these events.



The problem is strange and unpredictable behavior which I have traced down to a problem with multiple threads accessing the Swing GUI. So I tried to use the SwingUtilities.invokeLater to ensure that the calls were occurring on the Event Dispatch thread. Still have strange and unpredictable behavior....



Below is an excerpt of the thread dump:


Group main,ac=21,agc=4,pri=10
main,5,alive
AWT-Shutdown,5,alive
AWT-Windows,6,alive,dameon
AWT-EventQueue-0,6,alive
Main Console Writer,6,alive
TimerQueue,5,alive,dameon
Thread-15,5,alive
Group http://localhost:8080/xxx/-threadGroup,ac=4,agc=0,pri=4
thread applet-reqeditorpopup.editRequirement,4,alive
AWT-EventQueue-1,4,alive
TimerQueue,4,alive,dameon
thread applet-reqeditorpopup.editRequirement.class,4,alive


Now I have not one AWT-EventQueue, but two of them (actually each applet has its own). And therein is the problem. When I use invokeLater to process an event originating in the JavaScript, it uses EventQueue-0, however if I click on a component in the window, that event is processed on EventQueue-1. The JFrame class inits on EventQueue-1.

Sooner or later, there is going to be an argument between these two threads. Using the isDispatchThread doesn't help, because it always returns true.



Can anyone help me figure out how to get all of my events executing on one Event Dispatch thread? Seems to me they should go on the individual applets thread, but how do I get there?

   <<Less
About | Sitemap | Contact