Threads Monitor system time every 5 seconds

Source: Internet
Author: User

Package alarm;

Import Java.text.SimpleDateFormat;
Import Java.time.format.FormatStyle;
Import Java.util.Date;
Import Java.util.Timer;
Import Java.util.TimerTask;

Import Javax.xml.ws.Response;

public class Testtimerwu {
public static void Main (string[] args) {
TimerTask task = new TimerTask () {

@Override
public void Run () {
TODO auto-generated method stubs
SimpleDateFormat df = new SimpleDateFormat ("Yyyy-mm-dd HH:mm:ss");
String ss= Df.format (New Date ());
String Shifen = ss.substring (one, All). ToString ();
System.out.println (Shifen);
if (("21:56"). Equals (Shifen)) {

System.out.println ("Time Is up");
}else{
System.out.println ("The time has not arrived");
}

}
};
Timer timer=new timer ();
Timer.schedule (task, 0,1000);//indicates that the above thread is started every 5 seconds
}
}

Test class

Package alarm;

public class Test {
public static void Main (string[] args) throws Interruptedexception {
Testtimerwu.main (args);

}

}

Threads Monitor system time every 5 seconds

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.