-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSleep.java
More file actions
37 lines (32 loc) · 733 Bytes
/
Sleep.java
File metadata and controls
37 lines (32 loc) · 733 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
package com.study.thread;
public class Sleep extends Thread {
public static void main(String[] args) {
Sleep sleep = new Sleep();
sleep.start();
try {
int count = 0;
while (count < 5) {
sleep.join(1000);
count++;
System.out.format("%d second waited\n", count);
}
if (sleep.isAlive()) {
sleep.interrupt();
}
} catch (Exception e) {
e.printStackTrace();
}
}
@Override
public void run() {
try {
Thread.sleep(10000);
} catch (InterruptedException e) {
System.out.println("Somebody Stopped me.");
} catch (Exception e) {
e.printStackTrace();
} finally {
System.out.println("finally");
}
}
}