I have a login frame that i have to wait for from another thread. Upon successful login frame disposes itself. And i want to pop up the main frame for the application. Right now i am watching a boolean value to determine when to fire up the main frame. What is the correct way of doing this? Watching a boolean value just does not feel elegant.
Share
If you have Java 5 or later available, you could use a CountDownLatch. For example, assuming the main frame is in control initially, have the main frame create the
CountDownLatchwith a count down of 1 and pass this latch to the login frame. Then have the main frame wait for the latch to become 0:Have the login frame, when done, decrement the Latch:
Ensure that there is no way for your login frame to exit where it forgets to decrement the latch! As soon as the
CountDownLatchreaches 0, the main frame becomes runnable.You could also use a
SemaphoreorCondition(or any of a few other choices fromjava.util.concurrent), but for this purpose, aCountDownLatchseems easier to use.