26)Write a program to show the assignment of thread priorities.

PHOTO EMBED

Mon Jul 08 2024 06:21:34 GMT+0000 (Coordinated Universal Time)

Saved by @varuntej #java

class MyThread extends Thread {
    public void run() {
        System.out.println("run method");
        System.out.println("run method priority: " + Thread.currentThread().getPriority());
        Thread.currentThread().setPriority(4);
        System.out.println("run method priority after setting: " + Thread.currentThread().getPriority());
    }

    public static void main(String[] args) {
        System.out.println("main method");
        System.out.println("main method priority before setting: " + Thread.currentThread().getPriority());

        Thread.currentThread().setPriority(9);

        System.out.println("main method priority after setting: " + Thread.currentThread().getPriority());
    }
}
content_copyCOPY