swing action listener callback and wait/notify


Last month I asked “Exactly which thread calls the callback method in a Swing action listener when I click on a mouse?” I think Answer is, the EDT or “AWT event queue thread” in debugger thread listing.

This thread is started when the app starts and it waits in Object.wait() — confirmed. When you click on a button in the swing JFrame, the callback method runs in this thread. System doesn’t create a new thread to run the callback method. I think that would be too expensive since creating a new thread is not cheap. There are other fundamental reasons to run all event callbacks on EDT — see other posts in my blog.

For JMS onMessage() callback, I guess it might be similar — a single dedicated, long-running thread, not 5 new threads for 5 new messages. The volume of incoming messages is way too high if we create a new thread each time.

Next question is, what is this dedicated thread doing when there’s a long quiet period? I think it has to do a wait(), just like Swing.

Your input is welcome.


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s