forked from brianway/java-learning
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRun1_timer1.java
More file actions
33 lines (28 loc) · 850 Bytes
/
Copy pathRun1_timer1.java
File metadata and controls
33 lines (28 loc) · 850 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
package com.brianway.learning.java.multithread.timer.example1;
import java.util.Calendar;
import java.util.Date;
import java.util.Timer;
/**
* Created by Brian on 2016/4/15.
*/
/**
* P242
* schedule(TimerTask task, Date time)测试,在未来执行的效果
* Timer的构造方法会新启一个线程,且非守护线程
*/
public class Run1_timer1 {
public static void main(String[] args) {
System.out.println("当前时间为:" + new Date());
Calendar calendar = Calendar.getInstance();
calendar.add(Calendar.SECOND, 5);
Date runDate = calendar.getTime();
MyTask task = new MyTask();
Timer timer = new Timer();
timer.schedule(task, runDate);
}
}
/*
输出:
当前时间为:Fri Apr 15 22:10:14 CST 2016
任务执行了,时间为:Fri Apr 15 22:10:19 CST 2016
*/