Timer articles---java.util.TimerTask and quarts

Source: Internet
Author: User

Recent projects have appeared in the timing of the task of the things, research, think very good, and later use to get, summed up the next.

Only two types of java.util.Timer and quarts are introduced here.

Java.util.Timer

Java comes with a tool class that the thread uses to schedule tasks to perform later in the background thread. You can schedule a task to execute once, or repeat it periodically, and use it with Java.util.TimerTask for ease of use. The sample code is as follows:

ImportJava.util.Timer;ImportJava.util.TimerTask; Public classtes { Public Static voidMain (string[] args) {Timer timer=NewTimer (); Timer.schedule (NewMytimertask (), 1000, 2000); }}classMytimertaskextendstimertask{@Override Public voidrun () {System.out.println ("================"); }}

The code is simple and easy to use, but the java.util.TimerTask can only be executed at regular intervals and cannot be repeated at a fixed point in time.

Quarts

Quarts can be configured to perform tasks at a fixed point in time, which is slightly more complex, but powerful.

Today's time is not enough, head a bit uncomfortable, tomorrow research research and write again.

Timer articles---java.util.TimerTask and quarts

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.