Applet thread safety issues
I have been converting a number of applets from jdk 1.3 to 1.4.2. I have noticed many peculiarities, like intermittently focus is incorrect or gets lost, or several blinking carets start appearing, or even none. On getting a tip that there might be thread safety issues, I liberally sprinkled my code with println of
SwingUtilities.isEventDispatchThread() and
Thread.currentThread().getName().
I ran the compiled code under JBuilder as well as a signed applet in IE browser. This is what I discovered:
1. In the initial bringup of the form, the main thread returned isEventDispatchThread=false and thread name of main (JB) or class name (IE). ActionPerformed methods returned the same results. FocusGained and Lost returned isEventDispatchThread=true and thread name of AWT-EventQueue-1 or AWT-EventQueue-3. I noticed the threads were interfering with one another.
2. Once the form was up, all of the methods returned isEventDispatchThread=true and the thread name was AWT-EventQueue-1 or AWT-EventQueue-3. I noticed that AWT-EventQueue-1 threads interrupted AWT-EventQueue-3 threads.
The questions I have for you are:
1. On the initial bringup of the form, why do focus gain and lost use awt event queue threads but actionPerformed uses the main thread?
2. On the initial bringup, how can I force everything (main, actionPerformed, focus gain/lost) to run under the same thread?
3. What determines which awt event queue thread focus gain and lost will operate under since they are invoked asynchronously?
Anup

