-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy paththread.java
More file actions
45 lines (42 loc) · 1.09 KB
/
thread.java
File metadata and controls
45 lines (42 loc) · 1.09 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
class A extends Thread {
public void run() {
for (int i = 0; i <= 5; i++) {
if (i == 2)
Thread.yield();
System.out.println("Hello from A: i= " + i);
}
System.out.println("Exit from A");
}
}
class B extends Thread {
public void run() {
for (int j = 0; j <= 5; j++) {
if (j == 3)
stop();
System.out.println("Hello from B: j= " + j);
}
System.out.println("Exit from B");
}
}
class C extends Thread {
public void run() {
for (int k = 0; k <= 5; k++) {
if (k == 6) {
try {
sleep(5000);
} catch (Exception e) {
System.out.println("Some error");
}
}
System.out.println("Hello from C: k= " + k);
}
System.out.println("Exit from C");
}
}
class thread {
public static void main(String[] args) {
new A().start();
new B().start();
new C().start();
}
}