Created
May 11, 2015 19:51
-
-
Save InputNeuron/be4bd7b39c250b2b1a0c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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