I saw in another question regarding swing Timer API and your methods, preference stop();
my question is, is it possible to stop (cancel if util.timer) a timer when it’s currently executing?
I have a timer and need to stop a thread when I call stop(), even if it is currently running.
Yes, it is possible to stop a Swing Timer by calling
stop(). That’s why this class has this method. Having said this, I have a feeling that there is more to your problem then you are telling us. But I don’t know what a Swing Timer has to do with “stopping threads”.Edit
You state:
One possible solution: You could have the Swing Timer, but just enclose most of its code in an if statement controlled by a boolean say called, runTimer, so that the code in the Timer’s actionPerformed only runs if the boolean is true. Then run your background thread in a SwingWorker, but set the runTimer boolean to false before executing the SwingWorker, and then set it to true in the SwingWorker’s
done()method.