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:MainClass.java

public static void main(String[] args) {
    Timer timer = new Timer();

    timer.schedule(new DisplayQuestionTask(), 0, 10 * 1000);

    try {//from   w ww. j  ava2s.  c  o  m
        Thread.sleep(10000);
    } catch (InterruptedException e) {
    }

    timer.cancel();

}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    int delay = 5000; // delay for 5 sec.
    int period = 1000; // repeat every sec.
    Timer timer = new Timer();

    timer.scheduleAtFixedRate(new TimerTask() {
        public void run() {
            System.out.println("doing");
        }//from ww w  . j a  v a2  s  .  c  o m
    }, delay, period);
}

From source file:Main.java

public static void main(String[] args) {
    cb = new CyclicBarrier(2);
    Timer t = new Timer();
    t.schedule(new MyTimerTask(cb), 1000, 1000);
    while (true) {
        try {//from w w  w  .jav a2  s. c o  m
            cb.await();
        } catch (Exception e) {
        }
        System.out.println("main");
    }
}

From source file:Main.java

public static void main(String[] argv) throws Exception {

    Date timeToRun = new Date(System.currentTimeMillis() + numberOfMillisecondsInTheFuture);
    Timer timer = new Timer();

    timer.schedule(new TimerTask() {
        public void run() {
            System.out.println("doing");
        }/*from ww w . j av a2 s  .  c o m*/
    }, timeToRun);
}

From source file:GCTask.java

public static void main(String[] args) {
    Timer timer = new Timer();
    GCTask task = new GCTask();
    timer.schedule(task, 5000, 5000);/*from www . ja  v  a  2 s .  co m*/
    int counter = 1;
    while (true) {
        try {
            Thread.sleep(500);
        } catch (InterruptedException e) {
        }
    }
}

From source file:MyTimerTask.java

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

    timer.scheduleAtFixedRate(tasknew, 500, 1000);
}

From source file:MyTimerTask.java

public static void main(String[] args) {

    TimerTask tasknew = new MyTimerTask();
    Timer timer = new Timer();

    timer.scheduleAtFixedRate(tasknew, new Date(), 1000);
}

From source file:MyTimerTask.java

public static void main(String[] args) {

    TimerTask task = new MyTimerTask();
    Timer timer = new Timer();

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

    // cancelling the task
    System.out.println("cancelling task: " + task.cancel());
}

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);/*from w w  w .  java2  s. c  om*/
}

From source file:Main.java

public static void main(String[] args) {
    TimerTask task = new Main();

    Timer timer = new Timer();
    timer.scheduleAtFixedRate(task, new Date(), 1000);
}