This week's book giveaway is in the JavaScript forum.
We're giving away four copies of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js and have Paul Jensen on-line!
See this thread for details.
Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

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

 
Alistair Parler
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 55292
156
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 55292
156
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well done You have verified queuing for a simple example, so presumably queuing is normal behaviour.
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!