extends TimerTask : TimerTask : java.util : Java by API examples (example source code) Organized by topic

Java by API
C++
PHP


Java by API  »  java.util   » [  TimerTask  ]   
 



extends TimerTask

/*
 * Output:
Timer task executed.
Timer task executed.
Timer task executed.
Timer task executed.
Timer task executed. */

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

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

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

    /*
     * Set an initial delay of 1 second, then repeat every half second.
     */
    myTimer.schedule(myTask, 1000500);

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

    myTimer.cancel();
  }
}
           
       
Related examples in the same category
























Home| Contact Us
Copyright 2003 - 07 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.