Can set priority properly (SOLVED) | Sololearn: Learn to code for FREE!


Can set priority properly (SOLVED)

I have no idea how to set priority, can someone help? class Main { public static void main(String[ ] args) { Name name = new Name(); //set priority name.setPriority(1); Welcome welcome = new Welcome(); //set priority welcome.setPriority(2); name.start(); welcome.start(); } } //extend the Thread class class Welcome extends Thread { public void run() { System.out.println("Welcome!"); } } //extend the Thread class class Name extends Thread { public void run() { System.out.println("Please enter your name"); } }

3/26/2021 5:08:22 PM

Serana Zentha

6 Answers

New Answer


You have set it right.


Ahhh, ok, thanks so much Avinesh


Setting the priority doesn't guarantee that the Thread with higher priority will be executed first. It is more dependent on the OS and other internal factors. Assigning a higher priority to a thread just helps the thread get more CPU time for execution.


Avinesh it didnt work for me it wont print it in order, it only retrieves the numbers


Avinesh okay, I was just confused because the lesson this comes from told me to set priority but didnt tell me what it was for or what purpose it even served


I know 😉