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"); } }

26th Mar 2021, 5:08 PM
Serana Zentha
Serana Zentha - avatar
6 ответов
26th Mar 2021, 5:34 PM
Avinesh
Avinesh - avatar
+ 1
Ahhh, ok, thanks so much Avinesh
26th Mar 2021, 5:35 PM
Serana Zentha
Serana Zentha - avatar
+ 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.
26th Mar 2021, 5:50 PM
Avinesh
Avinesh - avatar
0
Avinesh it didnt work for me it wont print it in order, it only retrieves the numbers
26th Mar 2021, 5:39 PM
Serana Zentha
Serana Zentha - avatar
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
26th Mar 2021, 5:51 PM
Serana Zentha
Serana Zentha - avatar
0
I know 😉
26th Mar 2021, 5:52 PM
Avinesh
Avinesh - avatar