multithreading - Priorities are not working in threads in java -


this code snippet.

class thread1 extends thread {  thread1(string s)  {   super(s);  }  public void run()  {  for(int i=0;i<5;i++)  system.out.println(getname());  } } 

i have created 3 different classes 3 threads.

class thread2 extends thread {  thread2(string s)  {  super(s);  }  public void run()   {  for(int i=0;i<10;i++)  system.out.println(getname());  } }  class thread3 extends thread {  thread3(string s)  {  super(s);  }  public void run()  {  for(int i=0;i<12;i++)  system.out.println(getname());  } } 

simply trying print name of thread per priority set me.

class runthread extends thread {  public static void main(string... s)  {  thread1 t1= new thread1("t1");  thread2 t2= new thread2("t2");  thread3 t3= new thread3("t3"); 

but threads printing in same random way..as printed when no priority set.

 t1.setpriority(thread.norm_priority);  t2.setpriority(thread.min_priority);  t3.setpriority(thread.max_priority);  } } 

thread priority doesn't think does

  • it hint os can't ignore esp if not administrator or root.
  • it makes difference if have full utilisation of cpus. if cpus busy, can use priority decide how time each 1 gets. if have free cpus every thread can run regardless of priority.
  • the time takes start thread not instant. thread can take 0.1 ms 10 ms start, , in time thread can print many thousands of lines of output.

note: java uses native threads (in every modern jvm) means os not java scheduling.


Comments

Popular posts from this blog

jOOQ update returning clause with Oracle -

java - Warning equals/hashCode on @Data annotation lombok with inheritance -

java - BasicPathUsageException: Cannot join to attribute of basic type -