Skip to content

Instantly share code, notes, and snippets.

@fsamin
Created December 9, 2015 19:38
Show Gist options
  • Save fsamin/ec5aa79bc23965eca277 to your computer and use it in GitHub Desktop.
Save fsamin/ec5aa79bc23965eca277 to your computer and use it in GitHub Desktop.
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