线程-定时任务

//1000 表示延迟1秒执行,   5000表示每5秒执行一次
public
static void main(String[] args) throws InterruptedException { new Timer().schedule(new TimerTask() { @Override public void run() { System.out.println(Thread.currentThread().getName() + " run ");
          if(关闭任务条件){
            System.gc();
            cancel();
          }
} },
1000 , 5000); }
原文地址:https://www.cnblogs.com/redhat0019/p/9335247.html