📄 scheduler.java
字号:
package com.javapatterns.chainofresp.scheduler;
import java.util.*;
import java.io.IOException;
public class Scheduler
{
private static Timer timer = new Timer();
public static void main(String []args)
{
Calendar calendar = Calendar.getInstance();
calendar.set(Calendar.HOUR_OF_DAY, 10);
calendar.set(Calendar.MINUTE, 30);
calendar.set(Calendar.SECOND, 30);
Date time = calendar.getTime();
timer.schedule(new ScheduledTask(), time);
System.out.println("A job has been scheduled at " + time);
}
static class ScheduledTask extends TimerTask
{
public void run()
{
try
{
String command = "notepad c:/boot.ini";
Process child = Runtime.getRuntime().exec(command);
System.out.println("The scheduled job has been executed.");
}
catch (IOException e)
{
System.out.println("Exception " + e);
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -