My code has a UI thread that updates a Boolean variable. The problem I'm having is I want the main program to continuing executing when the variable becomes true.
public static void main(String[] args) throws Exception{
//Display the UI by creating an instance of Node
Node node = new Node();
//Wait for the node to connect to a router before continuing
while(!isConnectedToRouter);
//Do other things
}
While debugging I noticed the main thread suspends itself so main never gets to "Do other things". Even after another thread makes the boolean isConnectedToRouter true. If i change the while loop to
//Wait for the node to connect to a router before continuing
while(!isConnectedToRouter){
Thread.sleep(1);
}
It works, but It makes me aware that I'm doing something wrong. Any help would be appreciated.