I have such a code:
final SwingWorker worker = new SwingWorker() {
@Override
protected Object doInBackground() throws Exception {...};
}
Timer timer=new Timer(10000, new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
worker.execute();
}
});
timer.start();
Sometimes worker procedure takes more than 10 seconds, but sometimes 3-4sec, so how to set the timer to wait for the full execution of worker ? Any suggestions?
See the javadoc of the
SwingWorkerclass:So events are fired when the
SwingWorkeris done. Attach a listener and re-activate yourTimeron the correct event.