I have a small program presenting the user with a GUI to select a file, the program then executes based on the files contents and presents the results accordingly.
This is the loop running in the main thread (the main()
method):
do {
args = fg.getFile();
} while (!fg.started);
fg.started
is a boolean variable set to true when the user has selected a file and presses the "start" button.
However, this does not work UNLESS I put a random task inside the loop:
do {
args = fg.getFile();
System.out.println("");
} while (!fg.started);
This works.
Can anyone explain to me why this is?
I'm aware of a solution involving the Thread class, with notify()
and wait()
etc, but now I'm just curious about this.