Java Timer starts executing program

Source: Internet
Author: User

 Packagecom.zx.ps.web.gzdb;ImportJava.util.Calendar;Importjava.util.Date;ImportJava.util.Timer;ImportJava.util.TimerTask; Public classCKx {//Initialize Count    Static intCount = 0;  Public Static voidShowtimer () {FinalTimer timer =NewTimer (); //Create a timer taskTimerTask task =NewTimerTask () {@Override Public voidrun () {++count; System.out.println ("Time =" +NewDate () + "performed" + Count + "Times");//1 plays                Switch(count) { Case3: Timer.cancel (); System.out.println ("Scheduled time runs three times to end timed tasks!" ");  Break;                }            }        }; //Set Execution TimeCalendar Calendar =calendar.getinstance (); intYear =Calendar.get (calendar.year); intmonth =Calendar.get (Calendar.month); intDay = Calendar.get (calendar.day_of_month);//Daily//Customizing the Daily 11:40:00 execution,Calendar.set (year, month, day, 11, 58, 00); Date Date=Calendar.gettime (); intPeriod = 30 * 1000; //executes a task at the date of the day, repeating every 30 secondsTimer.schedule (task, date, period); //executes a task at the date of the day and executes only once//Timer.schedule (task, date);    }     Public Static voidMain (string[] args) {showtimer (); }}

Java Timer starts executing program

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.