Java timer in the usage of detailed _jquery

Source: Internet
Author: User

It is now used in the project to check whether the file is updated in a timely way. The timer is right here.

The usage is very simple, new a timer, and then write a timertask subclass.

The code is as follows:

Package comz.autoupdatefile; 
Import Java.util.Timer; 
Import Java.util.TimerTask; 
public class M {public 
  static void Main (string[] args) { 
    //TODO todo.generated by zoer 
    Timer timer = new Tim ER (); 
    Timer.schedule (New MyTask (), 1000, Watts); 
  } 
Class MyTask extends TimerTask { 
  @Override public 
  void Run () { 
    System.out.println ("dddd"); 
  } 

This allows the execution of MyTask to begin after 1 seconds, once every two seconds.

Of course, the timer's function can also construct the thread by itself, and then use sleep in the thread to simulate stopping for a while before performing an action.

In fact, look at the source of TimerTask can immediately know, TimerTask is the realization of the Runnable interface. That is, a timer is used to perform an operation over a period of time, but also through a thread.

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.