I think you were on track with your ScheduledExecutorService - you just need to hold on to the Future
it returns. Check out the cancel
method. I'm assuming you are using the schedule
method.
So basically you'd want to do something like
if (future != null) {
future.cancel();
}
future = // do scheduling code with ScheduledExecutorService