Example usage for java.util Timer Timer

List of usage examples for java.util Timer Timer

Introduction

In this page you can find the example usage for java.util Timer Timer.

Prototype

public Timer() 

Source Link

Document

Creates a new timer.

Usage

From source file:AutoTask.java

public static void main(String args[]) {
    AutoTask myTask = new AutoTask();
    Timer bkTimer = new Timer();

    bkTimer.schedule(myTask, 2000, 2000);

    for (int i = 0; i < 5; i++) {
        try {// ww w .  jav a  2s. co  m
            Thread.sleep(2100);
        } catch (InterruptedException exc) {
        }
    }
    bkTimer.cancel();
}

From source file:MyTimerTask.java

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

    // scheduling the task
    timer.scheduleAtFixedRate(task, new Date(), 1000);

}

From source file:MyTimerTask.java

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);// ww w.  java  2 s . c o m
}

From source file:MyTimerTask.java

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, new Date(), 1000);
}

From source file:MyTimerTask.java

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

    // scheduling the task
    timer.schedule(tasknew, new Date());
}

From source file:MyTimerTask.java

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

    // scheduling the task
    timer.scheduleAtFixedRate(task, new Date(), 1000);

    // checking scheduled execution time
    System.out.println("Time is :" + task.scheduledExecutionTime());
}

From source file:Main.java

public static void main(String... arguments) {
    TimerTask fetchMail = new Main();
    // perform the task once a day at 4 a.m., starting tomorrow morning
    Timer timer = new Timer();
    timer.scheduleAtFixedRate(fetchMail, getTomorrowMorning4am(), fONCE_PER_DAY);
}

From source file:MyTimerTask.java

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

    // scheduling the task
    timer.scheduleAtFixedRate(tasknew, new Date(), 10);

    // cancel task
    timer.cancel();//from w  ww.ja va 2s .  c  o  m

    // purging the timer
    System.out.println("purge value :" + timer.purge());
}

From source file:MyTimerTask.java

public static void main(String args[]) {
    MyTimerTask myTask = new MyTimerTask();
    Timer myTimer = new Timer();

    /*/*from  ww  w. jav a  2 s . co m*/
     * Set an initial delay of 1 second, then repeat every half second.
     */
    myTimer.schedule(myTask, 1000, 500);

    try {
        Thread.sleep(5000);
    } catch (InterruptedException exc) {
    }

    myTimer.cancel();
}

From source file:Main.java

public static void main(String[] args) {
    class SayHello extends TimerTask {
        Main thisObj = new Main();

        public void run() {
            String todaysdate = thisObj.CurrentDate();
            System.out.println(todaysdate);
        }/* w  ww . j  a v a  2s . c  o m*/
    }
    Timer timer = new Timer();
    timer.schedule(new SayHello(), 0, 5000);
}