-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDemo_Threads.java
More file actions
56 lines (48 loc) · 1.12 KB
/
Demo_Threads.java
File metadata and controls
56 lines (48 loc) · 1.12 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
//import java.lang.*;
import java.util.*;
@SuppressWarnings("unused")
class Thread1 extends Thread {
public void run() {
for(int i=1; i<=5; i++){
// if(i==1)
// yield();
// else
System.out.println("Thread1: "+i);
}
}
}
class Thread2 extends Thread {
@SuppressWarnings("removal")
public void run() {
for(int j=6; j<=10; j++) {
if(j==7)
stop();
else
System.out.println("Thread2: "+j);
}
}
}
class Thread3 extends Thread {
public void run() {
for(int k=11; k<=15; k++) {
if(k==13){
try{
sleep(1000);
} catch(Exception e){
}
}else{
System.out.println("Thread3:"+k);
}
}
}
}
public class Demo_Threads {
public static void main(String[] args) {
Thread1 t1 = new Thread1();
t1.start();
Thread2 t2 = new Thread2();
t2.start();
Thread3 t3 = new Thread3();
t3.start();
}
}