Question

Write a java program to create two threads and using setName method assign name to them also using setPriority method assign priority to those threads. Make necessary assumptions.

21 Jan 2021
Answer :
Word Count : 676

In Java, threads are independent paths of execution that can run concurrently. The `Thread` class is used to create and manage threads. Java provides methods like `setName()` to assign a name to a thread and `setPriority()` to assign a priority level to it. In this program, two threads are created, and each thread is assigned a name and priority.

The `setName()` method is used to set a custom name for the thread, which can help identify the thread in a multithreading environment. The `setPriority()` method allows setting the priority of a thread, which affects its scheduling. Thread priorities range from `Thread.MIN_PRIORITY` (1) to `Thread.MAX_PRIORITY` (10), with `Thread.NORM_PRIORITY` (5) being the default.

Here’s an example of how we can implement this:

```java
class MyThread extends Thread {
    public void run() {
________ _________ _____ ________ ___ _______ _______ ___ ____ ____.
_____ _______ _____ ___ __________ _______.
_____ _______ ____ ________ ______.
_______ _____ ____ ____ _______.
_________ ______ _________ ___ ________.
________ __________ _________ ________ _________ ___ __________ ____ _____ ______ _____ ______.
_______ ______ _____ _________ ___ _______ ___ __________.
___ __________ _________ _________ ______ _____ ___ ________ ______ ____ _____.
_______ ____ ____ ________ _______ ______ _________ _____ ___ ____ ________.
______ _____ _____ ____ __________ _________ __________ _____ _______.
___ _________ _______ ______ _______ ______ ____.
___ ________ __________ ____ _____ ____.
__________ ______ ___ _______ ____ ______ ____ _______ _________ _________ _______.
________ ___ _______ _______ ________ _______ ____.
____ _______ ___ ______ __________ _____ _____.
__________ _________ _______ ___ _____ ______ ___ ________.
________ ____ _______ ________ ________ ________ ____.
____ _______ __________ ________ _____ _________ ___ ____ ___ _____ _________.
_____ _______ ____ ____ _________ ___ __________ __________ ________ ____.
_____ __________ ___ _______ _________ __________ ________ ___ ____ _____ ________.
____ __________ ____ ___ _________ ____ _____ ___ ___ ____ ____ ___.
____ _______ ___ __________ _____ _______ _______ ____ __________ ___ __________ ________.
_____ ______ ______ _____ _______ ______ _________ _____ __________ ___ ____ __________.
____ ______ ________ __________ ________ ______ ______ ___ __________ __________ ___ _____.
_____ _______ ________ ____ _______ _______ ____ _____.
_______ _________ _______ ______ ________ _________ _________ __________ _________ ______ ________ ___.
______ _________ ______ ___ _________ ____ _________ _________ ____ _______.
_______ __________ ______ ______ __________ _____ _______ ___.
__________ _____ ____ _____ _______.
_____ ____ ___ ____ ___ _________ ____ _________ _____ _______ ________ ________.
_____ _____ __________ __________ ______ ____ __________ ______.
__________ ___ ____ ___ ______ _________ ____ __________ ____ ____ __________ _______.
________ _______ ______ __________ _____ ______ ________.
_______ _____ __________ ________ ___ ______ ________ ___ ________ _________ __________ ___.
___ _______ ______ ___ _____ ________ ________.
______ ____ _____ _____ __________ _______.
___ ______ ____ _______ _____ ________ _______ ____.
________ ______ ____ ______ ________ _____ ____ ____ _________ ____.
_______ ___ _________ __________ __________.
____ _____ ________ _____ ___.
________ _______ ____ _____ _________.
__________ _____ ________ _______ _____ _____ ______ ____.
_________ _____ ___ _______ _______ _______ ________ _______ ______ ____.
_____ __________ _____ _______ ___ ____ ____.
________ ____ __________ ______ _____ ________ ___ ________ ______ _____.
________ ______ ______ _______ _______ __________ ____ ______ __________.
_____ _________ ________ _____ ___ ___ ________ ______ ______ __________ ___.
__________ _____ __________ _________ ________ _______ __________ ____ _____ __________ _________.
________ _____ ________ __________ _____.
____ _____ __________ ________ __________ _________ ________ __________ ______ ____ _______.
__________ ________ _______ __________ ________ __________ __________ _______ ___ _____.
________ _______ _______ ___ __________ ___ _______.
_____ ____ ___ _______ ________.
___ _____ ____ ___ ___ __________ __________ _________ ______ _________ ____.
___ ____ __________ ______ _______ _______ __________ __________ __________ ________ ________.
__________ ___ _____ ______ ____.
_____ ____ ___ ________ _________ ________.
______ ___ ___ ___ ________ _________ ________ __________ _____.
_________ __________ ___ _______ ________.
___ ____ ________ _____ ____.
________ _____ _______ ________ ________ ______ ___.
________ __________ ____ ____ ________ __________ _______ ______ ____ _____ _____.
__________ __________ _______ ________ ___ _______ ________ ______ ________.
___ ___ _______.
Get Full Answer on WhatsApp

IGNOU NEWS
Assignment Submission Last Date Extended Till 30 June 2026 Click Here★★★IGNOU June 2026 TEE Date Sheet Released Click Here★★★
Top
📞
Call Support Instant phone assistance Write a java program to create two threads and using setName method as
🟢
WhatsApp Chat Fast live messaging
Email Us Business enquiries & support