I’ve got a worker thread that should wait for EDT to update the GUI before continuing execution. I’ve used the publish method to tell EDT to change something. How can i make the worker wait for that change to take place?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
If it is also your same worker thread that is initiating the GUI changes, then there’s a ready-built mechanism for waiting for those changes to be made:
SwingUtilities.invokeAndWait()
should fit the bill nicely.
Another alternative would be to use SwingUtilities.invokeLater() to give the EDT some code to run which will wake your thread up once the EDT becomes idle, i.e. when it gets around to running this task. This would involve firing off
invokeLater()immediately followed by await()and hoping that the wake-up from the EDI doesn’t happen before you do thewait(). This isn’t quite foolproof with respect to timing, though.