Created
December 9, 2015 19:38
-
-
Save fsamin/ec5aa79bc23965eca277 to your computer and use it in GitHub Desktop.
This file contains 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
import java.util.Timer; | |
import java.util.TimerTask; | |
/** | |
* Created by fsamin on 09/12/15. | |
*/ | |
public class MyTimer { | |
private final Timer t = new Timer(); | |
public TimerTask schedule(final Runnable r, long delay) { | |
final TimerTask task = new TimerTask() { | |
public void run() { | |
r.run(); | |
} | |
}; | |
t.schedule(task, delay); | |
return task; | |
} | |
public static void main(String[] args) { | |
MyTimer t = new MyTimer(); | |
Runnable task = () -> System.out.println("Task #1 is running"); | |
t.schedule(task, 500); | |
t.schedule(() -> System.out.println("Task #2 is running"), 500); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment