Skip to content

Instantly share code, notes, and snippets.

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

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

Select an option

Save InputNeuron/be4bd7b39c250b2b1a0c to your computer and use it in GitHub Desktop.
public class SchedulerTimerTask extends TimerTask {
private final AtomicReference<Runnable> task = new AtomicReference<Runnable>( null );
public SchedulerTimerTask(Runnable task) {
this.task.set( task );
}
public void run() {
Runnable delegate = this.task.get();
if ( delegate != null ) {
delegate.run();
}
}
/**
* Clear the reference to the runnable so it can be GCd
*/
public void clear() {
this.task.set( null );
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment