Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can there be more than one AWT event queue?

I've got a thread dump of an applet running on JVM 1.6.0_12 in Opera 9.64 Build 10487 - and it shows three event queues! As far as I know the Java Swing event handling is single threaded - did this change in any recent update?

My problem is, that multiple event queues will tend to cause deadlocks since I've got some more locks than only the GUI TreeLock.

like image 399
tigger Avatar asked Mar 20 '09 08:03

tigger


People also ask

How are waiting events processed in java AWT?

The User clicks the button and the event is generated. Now the object of concerned event class is created automatically and information about the source and the event get populated with in same object. Event object is forwarded to the method of registered listener class. the method is now get executed and returns.

What is an event queue?

EventQueue is a platform-independent class that queues events, both from the underlying peer classes and from trusted application classes.

Why is event queue used?

Event Queue to the Rescue An event queue is like a central station, a middle man where all “packages” arrive and are distributed to their corresponding destinations. This pattern decouples all communication using an event based system.


3 Answers

There can be more than one, and it depends on the browser. EventQueue documentation says:

Some browsers partition applets in different code bases into separate contexts, and establish walls between these contexts. In such a scenario, there will be one EventQueue per context. Other browsers place all applets into the same context, implying that there will be only a single, global EventQueue for all applets. This behavior is implementation-dependent.

like image 85
Joonas Pulakka Avatar answered Nov 08 '22 16:11

Joonas Pulakka


Yes. Typically there will be only one Toolkit for Toolkit.getDefaultToolkit, but multiple EventQueues from Toolkit.getSystemEventQueue (which from 1.2.2 you typically get permissions to call successfully). There is magic based on ThreadGroup and ClassLoaders on the stack to determine which EventQueue to return.

Applets are partitioned dependent upon their origin and configuration. Exactly how this is done is implementation dependent.

Now, what you are probably seeing is an event queue for your applet and the secure context. The secure context handles the dialog boxes from the plugin itself. Accepting certificates and things like that. The secure context keeps these away from user code in your applet context.

like image 32
Tom Hawtin - tackline Avatar answered Nov 08 '22 16:11

Tom Hawtin - tackline


In addition, Swing creates a new EventQueue (and thread IIRC) when you show a modal dialog, this event queue is active (the previous one is "on hold") until the modal dialog is closed.

However, I'm not sure what happens when having several levels of modal dialogs (1 main queue + 1 queue per dialog, or 1 main queue + 1 queue for all dialogs).

like image 27
jfpoilpret Avatar answered Nov 08 '22 17:11

jfpoilpret