Code example for Timer

Methods: scheduleAtFixedRate

0
 
        // 
        // Create a new timer to schedule the TimerExample instance at a 
        // periodic time every 1000 milliseconds and start it immediately 
        // 
        Timer timer = new Timer();
        timer.scheduleAtFixedRate(task, new Date(), 1000);
    } 
 
    /** 
     * This method is the implementation of a contract defined in the TimerTask 
     * class. This in the entry point of the task execution. 
     */ 
    public void run() { 
        // 
        // To make the example simple we just print the current time. 
        // 
        System.out.println(formatter.format(new Date()));
    } 
} 
Contextual code suggestions in your IDE  Get Codota for Java