0% found this document useful (0 votes)
66 views

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
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
66 views

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
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

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy