I have some Java Swing login panel. When user click “login” button, extensive DB communication takes place. I got an idea to put that db communication into another thread (that db communication is used for filling some hash maps and singletons). After putting that communication into separate thread, db heavy lifting takes place while user is typing it’s uname and password. When user clicks “login” button, than code will wait for “heavy lifting” thread to join, and then proceed.
The problem is that while my code is waiting for db thread to join, it seems that no UI updates can be done. I don’t think i can use SwingWorker for db communication because user can click “login” button any time, even before SW would finish and i don’t have a way to join SwingWorker (db communication has to take place BEFORE actual login).
Is there a way to enable Swing ui updates while waiting for another thread to join? Am i missing something?
Simply put two flags and at the end of both operations (DB-communication and user click), call the same method and verify there the state of the two flags. Possibly show a progress bar in a modal dialog if you want to block user input: