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