Question

Write a java program to demonstrate use of thread priority and how interthread communications take place.

01 Mar 2026
Answer :
Word Count : 585
In Java, threads are used to perform tasks concurrently. Thread priority is an integer value that determines the importance of a thread relative to others. Threads with higher priority are generally scheduled before threads with lower priority. Java provides a method `setPriority(int priority)` to set the priority of a thread, where the priority values range from `Thread.MIN_PRIORITY (1)` to `Thread.MAX_PRIORITY (10)`, with `Thread.NORM_PRIORITY (5)` as the default. Inter-thread communication in Java allows threads to communicate with each other using methods like `wait()`, `notify()`, and `notifyAll()`. These methods are part of the `Object` class, and they facilitate synchronization between threads. Threads can wait for a condition to be met using `wait()`, and notify other threads to continue execution using `notify()` or `notifyAll()`. Let's write a Java program to demonstrate both thread priority and inter-thread communication: ```java class ThreadExample extends Thread { private final int threadNumber; ThreadExample(int threadNumber) { this.threadNumber = threadNumber; } @Override public void run() { for (int i = 0; i < 5; i++) { try { System.out.println("Thread " + threadNumber + " running with priority " + getPriority()); Thread.sleep(1000); // Simulate work by sleeping for 1 second } catch (InterruptedException e)
_________ _______ _________ __________ ____.
__________ ________ ______ _____ _______ _____ ___.
_________ ___ _____ ______ ______ ________ ______ _____ _____ _______ ________ __________.
____ _____ ________ _______ _________ __________ ________ __________ _______ _______ _________ _____.
_________ _____ _______ ___ ____ _________ ________ _____ _____ _____ ________ _________.
______ ________ __________ ___ ______ ______ _________ __________.
________ ______ _____ ______ _______.
_______ ________ ___ ____ _______ ____ _______ ___.
_______ _______ __________ ______ __________ __________.
________ ______ _______ ________ ___ ________ _______ ______.
____ ____ ________ _______ ___ ______ ________ ___ _____ ____.
________ ________ ______ _____ _______ _________ _____ ___ __________ ___.
______ ____ _________ __________ _______ _______ ________ ___ ______ ________.
_______ ______ _______ ______ _____ ________ ______ _____ ________ _________ __________ _____.
__________ _______ _________ ____ ____ ____ ___ _________ _____ ___ _________ _____.
_________ ________ ________ ___ ____ __________ ______ ___ ________.
______ ______ _______ _________ ____ ______ ____ ____ _____ __________.
_____ __________ ________ __________ ________ _________ _______ ____ _______ ______.
_________ _____ _________ ___ __________ ______.
_________ _____ ________ ______ ____ ______.
_____ _________ _____ _______ ______ ________.
_____ _____ ________ _______ ______ ________ _____ ________.
______ _____ ___ _________ _______ ___ ____.
_______ ________ ________ ______ _____ ________ __________ ___ __________ _____ ________.
___ ________ ________ ____ ______ __________ ___ _________ _____ ________.
____ ________ ________ ________ __________ ________ ____ __________ ______.
_______ ______ _______ ____ ________ ______ _______.
_____ _______ _______ _______ ___ ___ ______ __________ ___.
______ ___ _________ ________ _________ ____ _________ ________ ________ ________ _____ ____.
_________ ____ __________ ____ _____.
_________ _____ _______ ________ ____ ___ ___ ______ ________.
______ ________ _______ ______ _________ _______.
_____ _________ _________ ________ __________.
_________ _____ ____ _______ _____ _____ _______ _____ _____ _____ _________.
___ ___ _____ ____ _________ __________ __________ _________ ____ ______ __________.
______ ____ _____ _____ _____ _________.
__________ ____ ___ __________ _____ _________.
____ ____ _________ ____ _____ __________ ____.
____ ___ ______ ___ ______ _______ _________ __________ ___.
_________ ___ _________ ________ ______.
_______ ____ _________ ____ ____.
____ _______ ____ ____ __________ __________ ______ _________ ________ _______ ____.
_____ ____ _______ ________ ___ __________ _______.
_______ ______ _____ ___ _______ _____ _______ __________.
______ ______ ________ _________ _______.
_________ ___ _______ ______ __________ _____ ___ __________ ____ _______ ___ ______.
____ ______ ______ __________ ___.
___ ___.
IGNOU ACADEMY
Your IGNOU journey, made easier.
  • Solved Assignments
  • Study Notes
  • Guess Papers
  • Question Papers
Skip in 10
Top
📞
Call Support Instant phone assistance IGNOU BCSL 146 2026 - Write a java program to demonstrate use of thread priority and how int | IGNOU Academy
→
🟢
WhatsApp Chat Fast live messaging
→
Email Us Business enquiries & support
→