Java Timer Task Timer schedule detailed

Source: Internet
Author: User

Don't talk about gossip, just go to the demo.

[Java]View Plaincopy
  1. Public class timertask {
  2. Public Static inti=1;
  3. Public Static classTesttaskextendstimertask{
  4.         public   void  run () {  
  5.              System.out.println ( +i+++ " Span class= "string" style= "margin:0px; padding:0px; Border:none; Color:blue; Background-color:inherit ">" sub-timer task "
  6. }
  7. }
  8. Public Static voidMain (string[] args)throws parseexception{  
  9.          date date=new  simpledateformat ( " Yyyy-mm-dd hh:mm:ss " " 2014-10-17 10:27:00 "
  10.         date firsttime=date;   
  11.         long  delay= 6000 ;  
  12.         long  period= 3000 ;  
  13.         timer timer1=new  timer ();   
  14.         timer timer2=new  timer ();   
  15.         timer timer3=new  timer ();   
  16.         timer timer4=new  timer ();   
  17.         testtask task=new  testtask ();   
  18.         //timer1.schedule (task, date);   
  19.         //timer2.schedule (task, delay);   
  20.         //timer3.schedule (task, firsttime, period);   
  21. Timer4.schedule (task, delay, period);
  22. }
  23. }

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.