Don't talk about gossip, just go to the demo.
[Java]View Plaincopy
- Public class timertask {
- Public Static inti=1;
- Public Static classTesttaskextendstimertask{
- public void run () {
- System.out.println ( +i+++ " Span class= "string" style= "margin:0px; padding:0px; Border:none; Color:blue; Background-color:inherit ">" sub-timer task "
- }
- }
- Public Static voidMain (string[] args)throws parseexception{
- date date=new simpledateformat ( " Yyyy-mm-dd hh:mm:ss " " 2014-10-17 10:27:00 "
- date firsttime=date;
- long delay= 6000 ;  
- long period= 3000 ;  
- timer timer1=new timer ();
- timer timer2=new timer ();
- timer timer3=new timer ();
- timer timer4=new timer ();
- testtask task=new testtask ();
- //timer1.schedule (task, date);   
- //timer2.schedule (task, delay);   
- //timer3.schedule (task, firsttime, period);   
- Timer4.schedule (task, delay, period);
- }
- }
The code defines a timed task Testtask, creates 4 timers, and each timer uses the schedule overloaded method
The timer1 is a task that executes a timed job at a specified time date.
The Timer2 is the task that executes the timed tasks after the delay millisecond delay.
Timer3 is the start of the Firsttime, which executes the scheduled task tasks and executes period milliseconds per interval.
Timer4 is a task that executes timed tasks after the delay millisecond delay, and executes once per interval of period milliseconds.
Java Timer Task Timer schedule detailed