scheduler.java

来自「java与模式 一书的源码」· Java 代码 · 共 41 行

JAVA
41
字号
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 + =
减小字号Ctrl + -
显示快捷键?