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

0

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

+3

You have set it right. https://code.sololearn.com/cJ4PELZOCOn9/?ref=app

+1

Ahhh, ok, thanks so much Avinesh

+1

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.

0

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

0

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

0

I know 😉