I am developing a data synchronizer, where every 5 seconds I check if there is data to be synchronized. The synchronization part with the check time every 5 seconds is already working. However, I was unable to make the progress bar follow the progress of the Task, that is, go from 0 to 100 at each iteration of the loop. Here is my code:
public void timerSincronizacao05Secs() {
Task sincronizacaoTask05Secs = new Task<Void>() {
@Override
protected Void call() throws Exception {
while (isRunning == false) {
isRunning = true;
System.out.println("iniciou em.....: " + new Date());
fachada.sincronizarProdutos();
barraProgresso.setProgress(0.50);
fachada.sincronizarClientes();
barraProgresso.setProgress(barraProgresso.getProgress() + 0.50);
System.out.println("terminou em.....: " + new Date());
isRunning = false;
try {
Thread.sleep(5000);
} catch (InterruptedException ex) {
break;
}
}
return null;
}
};
lblteste.textProperty().bind(sincronizacaoTask.messageProperty());
Thread threadSinv05Secs = new Thread(sincronizacaoTask05Secs);
threadSinv05Secs.setName("Thread sincronização a cada 5 segundos");
threadSinv05Secs.setDaemon(true);
threadSinv05Secs.start();
}
I know it's not the best way to do it, but if anyone can help, thank you right away!