Timer usage in Java

Source: Internet
Author: User
Original works can be reprinted. During reprinting, you must mark the original source, author information, and this statement in hyperlink form. Otherwise, legal liability will be held. Java. util. timer;

Import java. util. timertask; public class timerexample

{

/**

* Use of timers in Java

* Time:

*/

Timer localtimer;

Public timerexample (INT seconds)

{

// Create local Timer

Localtimer = new timer ();



// Create local timer task and set the timer-Parameter

Localtimer. Schedule (New localtimertask (), 0, seconds * 1000 );

}



Class localtimertask extends timertask

{

Int bittest = 0 xffffffff;

Int flag = 1;

Int temp = bittest;



// Override the abstract method of timertask

// The run () will be called every per Timer

Public void run ()

{

If (temp <0)

{

System. Out. println (integer. tobinarystring (temp ));

Temp = bittest &(~ Flag );

Flag <= 1;

}

Else

{

System. Out. println ("Time is up .");

Localtimer. Cancel ();

}

}

}



Public static void main (string [] ARGs)

{

New timerexample (1 );

}

}

This article is from the "select" blog, please be sure to keep this source http://programs.blog.51cto.com/785537/258747

Related Article

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.