Posted by
Michael Schmid on
Feb 28, 2014; 2:35pm
URL: http://imagej.273.s1.nabble.com/ImageListener-tp5006715p5006716.html
> I would like to exit from a synchronized while (image not updated)
> wait() (until the image is updated) loop when the image is not updated.
Hi Philippe,
it seems that you need some timeout, otherwise you can't know whether an update is still to come. Maybe roughly like this:
//class variables ('global')
ImagePlus theImageIamWaitingFor;
Thread waitingThread;
public void imageUpdated(ImagePlus imp) {
if (imp == theImageIamWaitingFor && waitingThread != null)
waitingThread.interrupt();
}
//main processing code
...
waitingThread = Thread.currentThread();
theImageIamWaitingFor = ...
while (true) { //might be also while (!closed) etc.
//do some analysis on updated image
synchronized(this) {
//wait for image update, but no longer than 1000 millesec:
try {
wait(1000);
} catch (InterruptedException e) {
continue; //loop again after update
}
break; //timeout, leave the while loop
}
}
Michael
________________________________________________________________
On Feb 28, 2014, at 14:05, Philippe GENDRE wrote:
> Dear List,
>
> I would like to exit from a synchronized while (image not updated) wait()
> (until the image is updated) loop when the image is not updated.
>
> Is it possible and how to ?
>
> Thanks.
>
> Philippe
>
> --
> ImageJ mailing list:
http://imagej.nih.gov/ij/list.html--
ImageJ mailing list:
http://imagej.nih.gov/ij/list.html