-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhitwo.java
51 lines (41 loc) · 1013 Bytes
/
hitwo.java
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
class Mythread extends Thread{
public void run(){
System.out.println("Current thread name : " +Thread.currentThread().getName());
}
}
class threadone extends Thread{
synchronized public void run(){
for (int i = 0; i < 5; i++) {
System.out.println("current thread 1 " + (i*-1));
}
}
}
class threadtwo extends Thread{
synchronized public void run(){
for (int i = 0; i < 5; i++) {
System.out.println("current thread 2 " + (i*2));
}
}
}
class threadthree extends Thread{
synchronized public void run(){
for (int i = 0; i < 5; i++) {
System.out.println("current thread 3 " + ((i*2)-1));
}
}
}
public class hitwo {
public static void main(String[] args) {
Mythread t = new Mythread();
t.start();
t.run();
synchronized(){
threadone t1 = new threadone();
t1.start();
threadtwo ts = new threadtwo();
ts.start();
threadthree re = new threadthree();
re.start();
}
}
}