-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTimerTest.java
More file actions
45 lines (36 loc) · 850 Bytes
/
Copy pathTimerTest.java
File metadata and controls
45 lines (36 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
34
35
36
37
38
39
40
41
42
43
44
45
package moreAboutJava;
import java.util.Timer;
import java.util.TimerTask;
class MyTimerTask extends TimerTask {
static int count = 0;
@Override
public void run() {
// TODO Auto-generated method stub
System.out.println(this);
System.out.println("mytimertask in run()" + " " + ++count);
}
}
public class TimerTest {
public static void main(String[] args) {
// TODO Auto-generated method stub
Timer timer = new Timer();
timer.schedule(new MyTimerTask(), 1000, 2000);
/**
while (true) {
try {
System.out.println("input >>> ");
int ch = System.in.read();
System.out.println("ch >>> " + ch);
if (ch - 'c' == 0) {
System.out.println("timer cancel");
timer.cancel();
break;
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
**/
}
}