0

I came across this question while learning Java threading: For a Swing application with two workers, the EDT is waiting for a GUI event, and both workers are waiting. Is this considered a deadlocked application?

I feel it's not as it's quite similar with "an idle status", when an application is waiting for user input. But if it's not, what is a deadlock is this scenario? EDT is waiting and both workers are running?

Lii
  • 11,553
  • 8
  • 64
  • 88

1 Answers1

0

Deadlock scenario is when you have 2 threads (or n theads) that are waiting for eachother to complete before proceeding - this will never happen.

In case of Event Dispatch Thread (single thread here so n=1) you can deadlock the thread if you submit new task to EDT for example via SwingUtilities.invokeAndWait()) from the code that is already executing in the EDT.

This way, SwingUtilities.invokeAndWait(Runnable) will wait until submited Runnable will finish, but in fact it will never start the execution because it is enqueued untill EDT is idle (whitch is the current thread) - and this will never happen.

App fill freeze, and you will be able only to move window, not ever resize it (well u will change size, but it will not be repained)

Please do not mistake Idle state and deadlock. Idle means that thread is simply doing nothing, for example awaiting new tasks. Deadlocking, is an error in programing and must be avoided.

Antoniossss
  • 31,590
  • 6
  • 57
  • 99