• Post Reply Bookmark Topic Watch Topic
  • New Topic

Thread Priority

 
sai donthneni
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a question in priority for thread.

I have a class "Priority" which impements Runnable and when I create a thread of class Priority from main of class ThreadPrioritDemo and set it to max_priority, why is this thread not getting priority over main() thread.

class ThreadPrioritDemo
{public static void main(String args[])
{
Priority pr=new Priority();
Thread tpr=new Thread(pr, "ThreadA");
tpr.setPriority(Thread.MAX_PRIORITY);
tpr.start();
Thread.currentThread().getName()="+Thread.currentThread().getName());

try
{
Thread.sleep(3000);
}
catch(InterruptedException e){ }
System.out.println("in main() -Thread.currentThread().getPriority()="+Thread.currentThread().getPriority());

}

}
 
sai donthneni
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
what exactly I want to ask is that when a thread is spawned from main() thread and which is set to maximum priority, then will the new thread be given more priority than the main() thread?
 
marc weber
Sheriff
Posts: 11343
Java Mac Safari
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by sai donthneni:
what exactly I want to ask is that when a thread is spawned from main() thread and which is set to maximum priority, then will the new thread be given more priority than the main() thread?

Thread scheduling -- determination of which threads run and for how long (per CPU time slicing) -- is largely platform dependent. In general, you should not use thread priority to try to force the order of execution. Think of priority as a "suggestion" -- not a command.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!