-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathScheduledExecutorServiceTest.java
More file actions
57 lines (44 loc) · 1.21 KB
/
ScheduledExecutorServiceTest.java
File metadata and controls
57 lines (44 loc) · 1.21 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
package moreAboutJava;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
public class ScheduledExecutorServiceTest {
private static ScheduledExecutorService scheduExec = Executors
.newScheduledThreadPool(1);
public static void main(String[] args) {
// TODO Auto-generated method stub
launchTask();
try {
Thread.sleep(1000 * 5);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
addTask();
}
private static void addTask() {
// TODO Auto-generated method stub
Runnable task = new Runnable() {
@Override
public void run() {
// TODO Auto-generated method stub
System.out.println("in addTask()");
}
};
scheduExec.scheduleWithFixedDelay(task, 1000, 1000,
TimeUnit.MILLISECONDS);
}
private static void launchTask() {
Runnable task = new Runnable() {
@Override
public void run() {
// TODO Auto-generated method stub
System.out.println("runtime exception");
throw new RuntimeException();
}
};
// TODO Auto-generated method stub
scheduExec.scheduleAtFixedRate(task, 1000 * 5, 1000 * 10,
TimeUnit.MILLISECONDS);
}
}