-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathThread_Priority1.java
56 lines (54 loc) · 1.33 KB
/
Thread_Priority1.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
52
53
54
55
56
class A extends Thread
{
public void run()
{
System.out.println("threadA started");
for(int i=1;i<=4;i++)
{
System.out.println("From thread A:i= "+i);
}
System.out.println("Exit from A");
}
}
class B extends Thread
{
public void run()
{
System.out.println("threadB started");
for(int j=1;j<=4;j++)
{
System.out.println("From thread B:j= "+j);
}
System.out.println("Exit from B");
}
}
class C extends Thread
{
public void run()
{
System.out.println("threadC started");
for(int k=1;k<=4;k++)
{
System.out.println("From thread C:k= "+k);
}
System.out.println("Exit from C");
}
}
public class Thread_Priority1 {
public static void main(String[]args)
{
A threadA = new A();
B threadB =new B();
C threadC = new C();
threadC.setPriority(Thread.MAX_PRIORITY);
threadB.setPriority(threadA.getPriority()+1);
threadA.setPriority(Thread.MIN_PRIORITY);
System.out.println("Start thread A");
threadA.start();
System.out.println("Start thread B");
threadB.start();
System.out.println("Start thread C");
threadC.start();
System.out.println("End of main thread");
}
}