In the above program, we created two classes MyThread and Main. We created MyThread class by implementing the Runnable interface.
The Main class contains a main() method. The main() method is the entry point for the program. Here, we created the three threads and set and get priorities of threads using setPriority(), getPriority() methods and printed the result.
Program/Source Code:
The source code to set thread priority is given below. The given program is compiled and executed successfully.
Output:
Explanation:
In the above program, we created two classes MyThread and Main. We created MyThread class by implementing the Runnable interface.
The Main class contains a main() method. The main() method is the entry point for the program. Here, we created the three threads and set and get priorities of threads using setPriority(), getPriority() methods and printed the result.