I am writing a program that is to do quite a lot of work in real time, its to process Images from a video and display the Images on a JavaFx ImageView, the issue is I cannot update main thread components from another thread, java is not thread safe so I though of a way of using a Timer instead, a thread keeps lagging behind, it mostly hangs, so below is how I have implemented my code
TimerTask frame_grabber = new TimerTask()
{
@Override
public void run()
{
processVideo();
Platform.runLater(new Runnable() {
@Override public void run() {
imageView.setImage(tmp);
}
});
}
};
timer = new Timer();
Double period = 1000 / getFPS() * 2;
this.timer.schedule(frame_grabber, 0, period.longValue());
This seems to work better but the my entire GUI is laggying, can someone suggest me a better way of processing the video and updating my UI without causing any lags?
TimerTaskmore often. To be more precise in any advice you probably should post the code forprocessVideoas well.