How can create threads?

There are two ways to create the threads:----

  • By extending thread class                                                                                         
  • By implementing Runable interface 



Best way is creating the threads by using the Runnable interface.
Reason :--- when you extend thread class we don’t have a chance  to extend some other java class where as  when you implement Runnable interface you can extend some other java class.
Can I overload run method? If I do what will happen to overloaded method?
Yes you can overload run method but there is no use, because JVM invokes only the run method whose signature is available in Runnable interface. You have to explicitly invoke the other overloaded run methods.
 Can I write a thread without overriding run method?
You can avoid overriding run method in the case of extending thread class, but you should override run() method in the case of implementing Runnable interface. 
Thread priority: -------- priority is a number which is given to the thread which will be used by the CPU scheduling algorithm to allocate the CPU time ..
This number is ranging from  1  to 10.
In the case of priority based scheduling algorithm this number will have a value i.e. the thread with highest priority will get the CPU time 1st vice versa.
In the case of non-priority based scheduling algorithm there is no use of this value.
In thread class three constant are defined related to this priority:---------
  •   MIN_PRIORITY               ------   1    --------priority value
  •     NORM_PRIORITY           ------   5
  •     MAX_PRIORITY              ------  10
In thread class two methods are defined related to priority :-------
     Int getPriority();
     Void setPriority(int);
  •     You can set the priority for the thread using the following method.  
  •      -----          setPriority(int p);
  •     You can get the existing priority of a thread using the following method    -----      int getPriority();
  • When I create the thread without specifying the priority then what will be the default priority?
  • Value of default priority = Five ------------- 5.
  • When I set the thread priority with the number greater than 10.what will happen.
An exception will rise at the run time. Java.lang.Illegal Argument Exception.