Implementation of the function in Java through the operation of the PC content by code

Source: Internet
Author: User

1, add the scheduled task, the user project needs to add the timing reminder function:

The task of scheduling is to write a class that inherits Java.util.TimerTask, overwriting the Run method, for example:

import java.util.*;  Public class extends timertask{@Overridepublic void  run () {//... code System.out.println ("updated");}}
Import Java.util.Timer;   New Timer ();  Timer.schedule (new updatedatatask (), 0, 3600000);  

2, through the code to achieve a timed shutdown, or restart the function, can be used to hang the machine running code ...

 Public Static voidshutdown () {System.out.print ("Please enter how many minutes after the shutdown:"); Scanner Scanner=NewScanner (system.in); intminute = Scanner.nextint () *60; Runtime Runtime=Runtime.getruntime ();
You can also write minute to a fixed time, or make simple changes to add to the last face of the code, after running the automatic shutdown String shutdown
= "Shutdown-s-T" +minute; Try{runtime.exec (shutdown); } Catch(IOException e) {e.printstacktrace (); } }

Implementation of the function in Java through the operation of the PC content by code

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.