S
Simon Andrews
I'm writing a class which can include a long IO-bound routine and I'm
trying to show a progress bar during the loading of this data. I've
separated the IO code into a seaprate thread which puts up a progress
pane to show what it's doing. This bit all works.
The problem is that my class returns a big data structure. Initially
this is empty and it is loaded dynamically the first time it's asked for
(using the separate threaded code). Subsequent calls use the pre-loaded
data and return quickly without doing the IO again.
The problem is how to get the call to the thread to wait for it to
complete before passing back the data structure. The code I'm using is
shown below. This works, but doesn't allow the window produced by
ProgressWindow to update. If I remove the while (!done) code the
progess window updates OK (and the data is loaded), but this method
returns instantly with a null value.
How can I make this method wait nicely for ProgressWindow to complete
whilst still allowing GUI updates to happen?
Cheers
Simon.
public Species [] getSpeciesOntology (Component c) throws IOException {
if (speciesList == null) {
// ProgressWindow is a new thread
ProgressWindow w = new ProgressWindow(c);
while (!w.done) {
System.err.println("Still waiting....");
try {
Thread.sleep(1000);
}
catch (Exception e) {
}
}
}
return speciesList;
}
trying to show a progress bar during the loading of this data. I've
separated the IO code into a seaprate thread which puts up a progress
pane to show what it's doing. This bit all works.
The problem is that my class returns a big data structure. Initially
this is empty and it is loaded dynamically the first time it's asked for
(using the separate threaded code). Subsequent calls use the pre-loaded
data and return quickly without doing the IO again.
The problem is how to get the call to the thread to wait for it to
complete before passing back the data structure. The code I'm using is
shown below. This works, but doesn't allow the window produced by
ProgressWindow to update. If I remove the while (!done) code the
progess window updates OK (and the data is loaded), but this method
returns instantly with a null value.
How can I make this method wait nicely for ProgressWindow to complete
whilst still allowing GUI updates to happen?
Cheers
Simon.
public Species [] getSpeciesOntology (Component c) throws IOException {
if (speciesList == null) {
// ProgressWindow is a new thread
ProgressWindow w = new ProgressWindow(c);
while (!w.done) {
System.err.println("Still waiting....");
try {
Thread.sleep(1000);
}
catch (Exception e) {
}
}
}
return speciesList;
}