KEMBAR78
Thread Priority | PDF
0% found this document useful (0 votes)
130 views1 page

Thread Priority

Three threads (A, B, and C) are created by extending the Thread class. Each thread prints out numbers from 1 to 4 and then prints "End of" the thread name. The main method creates instances of each thread, sets their priorities from highest (C) to lowest (A), and then starts each thread running.

Uploaded by

Sayani Chandra
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
130 views1 page

Thread Priority

Three threads (A, B, and C) are created by extending the Thread class. Each thread prints out numbers from 1 to 4 and then prints "End of" the thread name. The main method creates instances of each thread, sets their priorities from highest (C) to lowest (A), and then starts each thread running.

Uploaded by

Sayani Chandra
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1

// Thread Priority.

class A extends Thread


{
public void run()
{
for (int i = 1; i <= 4; i++)
{
System.out.println("ThreadA : " +i);
}
System.out.println("End of ThreadA");
}
}
class B extends Thread
{
public void run()
{
for (int j = 1; j <= 4; j++)
{
System.out.println("ThreadB : " +j);
}
System.out.println("End of ThreadB");
}
}
class C extends Thread
{
public void run()
{
for (int k = 1; k <= 4; k++)
{
System.out.println("ThreadC : " +k);
}
System.out.println("End of ThreadC");
}
}
class ThreadPriority
{
public static void main (String args [])
{
A a = new A();
B b = new B();
C c = new C();

c.setPriority(Thread.MAX_PRIORITY);
b.setPriority(a.getPriority()+1);
a.setPriority(Thread.MIN_PRIORITY);

a.start();
b.start();
c.start();
}
}

You might also like