-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRunnableThread.java
More file actions
33 lines (30 loc) · 794 Bytes
/
Copy pathRunnableThread.java
File metadata and controls
33 lines (30 loc) · 794 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
public class RunnableThread implements Runnable {
public int count = 0;
public void run() {
System.out.println("RunnableThread Starting.");
try {
while (count < 5) {
Thread.sleep(500);
System.out.println("In Thread, count is " + count);
count++;
}
}
catch (InterruptedException exc) {
System.out.println("RunnableThread Interrupted.");
}
System.out.println("RunnableThread Terminating");
}
public static void main(String[] args) {
RunnableThread instance = new RunnableThread();
Thread thread = new Thread(instance);
thread.start();
while (instance.count != 5) {
try {
Thread.sleep(250);
}
catch (InterruptedException exc) {
exc.printStackTrace();
}
}
}
}