-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSeveralTimerTest.java
More file actions
92 lines (70 loc) · 1.77 KB
/
SeveralTimerTest.java
File metadata and controls
92 lines (70 loc) · 1.77 KB
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
package moreAboutJava;
import java.util.Calendar;
import java.util.Date;
import java.util.Timer;
import java.util.TimerTask;
public class SeveralTimerTest {
static int count = 0;
public static void main(String[] args) {
// TODO Auto-generated method stub
timerTest1();
timerTest2();
// timerTest3();
timerTest4();
}
private static void timerTest4() {
// TODO Auto-generated method stub
Calendar calendar = Calendar.getInstance();
calendar.set(Calendar.HOUR_OF_DAY, 14);
calendar.set(Calendar.MINUTE, 20);
calendar.set(Calendar.SECOND, 0);
Date time = calendar.getTime();
Timer timer = new Timer();
System.out.println("wait ....");
timer.scheduleAtFixedRate(new TimerTask() {
@Override
public void run() {
// TODO Auto-generated method stub
System.out.println("timertest4");
}
}, time, 24 * 60 * 60 * 1000);
}
private static void timerTest3() {
// TODO Auto-generated method stub
Timer timer = new Timer();
timer.scheduleAtFixedRate(new TimerTask() {
@Override
public void run() {
// TODO Auto-generated method stub
System.out.println("timertest3");
}
}, 2000, 1000);
}
private static void timerTest2() {
// TODO Auto-generated method stub
Timer timer = new Timer();
timer.schedule(new TimerTask() {
@Override
public void run() {
// TODO Auto-generated method stub
if (count < 5) {
System.out.println("timertest2" + " " + ++count);
} else {
timer.cancel();
}
}
}, 2000, 1000);
}
private static void timerTest1() {
// TODO Auto-generated method stub
Timer timer = new Timer();
timer.schedule(new TimerTask() {
@Override
public void run() {
// TODO Auto-generated method stub
System.out.println("timertest1");
timer.cancel();
}
}, 2000);
}
}