0% found this document useful (0 votes)
3 views1 page

ThreadPriority Program

This Java program demonstrates multithreading by printing numbers from two different loops. It creates two threads, 'FirstLoop' and 'SecondLoop', with different priorities, where 'FirstLoop' has the highest priority and 'SecondLoop' has the lowest. Each thread prints numbers from 1 to 10 with a delay of 100 milliseconds between prints.

Uploaded by

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

ThreadPriority Program

This Java program demonstrates multithreading by printing numbers from two different loops. It creates two threads, 'FirstLoop' and 'SecondLoop', with different priorities, where 'FirstLoop' has the highest priority and 'SecondLoop' has the lowest. Each thread prints numbers from 1 to 10 with a delay of 100 milliseconds between prints.

Uploaded by

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

// Java Program: Print numbers from 2 different loops using Multithreading with Priority

class FirstLoop extends Thread {


public void run() {
for (int i = 1; i <= 10; i++) {
[Link]("First Loop: " + i);
try { [Link](100); } catch (Exception e) {}
}
}
}

class SecondLoop extends Thread {


public void run() {
for (int i = 1; i <= 10; i++) {
[Link]("Second Loop: " + i);
try { [Link](100); } catch (Exception e) {}
}
}
}

public class ThreadPriorityExample {


public static void main(String[] args) {

FirstLoop t1 = new FirstLoop();


SecondLoop t2 = new SecondLoop();

// Setting thread priorities


[Link](Thread.MAX_PRIORITY); // Highest priority
[Link](Thread.MIN_PRIORITY); // Lowest priority

[Link]();
[Link]();
}
}

You might also like