Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Timer;
- import java.util.TimerTask;
- public class TimeExecutor {
- class LocalSleep extends TimerTask {
- private int noOfSeconds;
- private int count = 0;
- private Timer timer;
- public LocalSleep(int noOfSeconds, Timer timer) {
- this.noOfSeconds = noOfSeconds;
- this.timer = timer;
- }
- void sleeeep() {
- if (count < noOfSeconds) {
- System.out.println("Count: " + count);
- count++;
- } else
- timer.cancel();
- }
- @Override
- public void run() {
- sleeeep();
- }
- }
- public static void main(String args[]) {
- Timer timer = new Timer();
- TimeExecutor t = new TimeExecutor();
- timer.schedule(t.new LocalSleep(5, timer), 1000);
- }
- }
- timer.schedule(t.new LocalSleep(5, timer), 1000);
- timer.schedule(t.new LocalSleep(5, timer),0, 1000);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement