Skip to content

Instantly share code, notes, and snippets.

@InputNeuron
Created May 11, 2015 19:50
Show Gist options
  • Select an option

  • Save InputNeuron/6fe3ee640f5f1b27caa2 to your computer and use it in GitHub Desktop.

Select an option

Save InputNeuron/6fe3ee640f5f1b27caa2 to your computer and use it in GitHub Desktop.
public synchronized void cancel(Runnable task) {
SchedulerTimerTask ticket = timerTasks.remove(task);
if (ticket != null) {
ticket.cancel();
// now clear the ticket so we can remove the reference to the
// underlying task. This is necessary to allow GC to take effect.
// Otherwise the Runnable will still have a reference and hog
// memory.
ticket.clear();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment