MyTimerTask.java Source code

Java tutorial

Introduction

Here is the source code for MyTimerTask.java

Source

import java.util.Date;
import java.util.Timer;
import java.util.TimerTask;

class MyTimerTask extends TimerTask {
    public void run() {
        System.out.println("Timer task executed.");
    }
}

public class Main {
    public static void main(String[] args) {
        // creating timer task, timer
        TimerTask tasknew = new MyTimerTask();
        Timer timer = new Timer();

        // scheduling the task at interval
        timer.schedule(tasknew, 100, 100);
    }

    // this method performs the task
    public void run() {
        System.out.println("timer working");
    }
}