I'm working on a Java Spring-MVC application that needs to refresh its screen upon completion of certain actions performed by a Java Web Start application that it kicks off. In a utility method called by the one that refreshes the screen, I create a thread to run a query to see if the action of the JWS app has completed, and if not, it goes to sleep for a few seconds then checks again. (After x number of tries, the thread breaks out of the loop.)
So my thread code is functioning the way I want it to, and will correctly catch when the action is complete, but the problem is that the method has moved on, so the screen refresh might happen before the status of the file in question has been updated. What should I be doing here: is there a way to make the refresh-screen method wait till the status-checker thread has completed, or should my thread be calling a method to refresh the screen?
I came to realize that the answer to my question was my former thought: make the method wait before refreshing the screen. I used Thread.sleep()
to pause the main thread of execution in the loop in which I check if the action of the Java Web Start application has completed. So no more creating a thread to do the checking, since that wasn't delaying the screen refresh till the appropriate time, anyway...