Could somebody please suggest me at what situation a progarm could run with the order that is not as it looks like.

eg: When the code should run sequencely, it does not.

In my case, I don't have many threads: I have a GUI and a main. The program will begin to run until it gets the GUI interface and then it stops to wait for me to press one button to continue. A lot of strange problems come out after that. This is one of it.

I am not sure where my problem resides, but it starts to be strange near something like the following (when it prints something. )


public void waitToStart(PrintWriter pW)throws IOException
{
while(!start){}
startRun(pW);
}
public void startRun(PrintWriter pW)throws IOException
{
while(!finished)
{
.
.
.
System.out.println("******");
pW.println("******");
pW.flush();
.
.
.
}
}


Any suggestions please. Thanks very much.