File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Swing / AWT / SWT and the fly likes What happens to events when an actionlistener is hogging the event dispatch thread Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "What happens to events when an actionlistener is hogging the event dispatch thread" Watch "What happens to events when an actionlistener is hogging the event dispatch thread" New topic
Author

What happens to events when an actionlistener is hogging the event dispatch thread

Alistair Parler
Greenhorn

Joined: May 24, 2009
Posts: 11
Hi,

This is probably a really dumb question, but I'd appreciate any help: I'm just curious.

If I have an actionlistener which is executing its actionPerformed inside the AWT event dispatch thread (i.e. we haven't done the correct thing of either doing the work in a new thread so it doesn't hog the event dispatch thread, or doing the work in an invokeLater if it manipulates any Swing components), what happens to the peer events from the OS when this is running: do they get queued ready for dispatch when the actionPerformed returns?


Thanks,
Alistair
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39436
    
  28
Welcome to JavaRanch

As far as I can remember, events (and anything else) queue until the thread is available, but I am not sure. You will have to try it out with two actionListeners; that might verify it. Does the threading policy link help?
Alistair Parler
Greenhorn

Joined: May 24, 2009
Posts: 11
Thanks Campbell!

I just wrote this program and tested it by clicking Btn1 and then Btn2 lots of times. After the sleep had completed, the remaining events were pumped, then the program terminated. So they are indeed queued.



Thanks,
Alistair
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39436
    
  28
Well done You have verified queuing for a simple example, so presumably queuing is normal behaviour.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: What happens to events when an actionlistener is hogging the event dispatch thread