TODAY JAVA SCHOOL

In java school, programming, design, computer general knowledge, web application, software, web services, social media, digital marketing, oops, concept of programming language, oops feature, console media, graphics medium, first programming, c, c ++ , Java, PHP, SQL, MySQL, HTML, HTML_5, J_query, JavaScript, Bootstrap, Framework, images with logos, examples, shared and explained.

https://www.amazon.in/b?node=26373545031&linkCode=ll2&tag=1234567801cdb-21&linkId=3b9882431b00409b44141e0344b35a15&language=en_IN&ref_=as_li_ss_tl

Breaking

Wednesday, 15 April 2020

Thread Priority In Java | Advantage Of Thread Priority In Java | Thread Priority In Hindi

Thread Priority

Priorities are represented by a number between 1 and 10. In most
cases, thread schedular schedules the threads according to their priority
 (known as preemptive scheduling). But it is not guaranteed because it
 depends on JVM specification that which scheduling it chooses.

advantage of thread priority in java

Fig: Thread priority 



3 constants defined in Thread class:

1.    public static int MIN_PRIORITY
2.    public static int NORM_PRIORITY
3.    public static int MAX_PRIORITY


Default priority of a thread is 5 (NORM_PRIORITY). The value of
 MIN_PRIORITY is 1 and the value of MAX_PRIORITY is 10.


Example of priority of a Thread:

      class TestMultiPriority1 extends Thread{  
       public void run(){  
           System.out.println("running thread name is:"+Thread.currentThread().g            etName());  
                 System.out.println("running thread priority is:"+Thread.currentThread().getPri    ority());  
  
    }  
     public static void main(String args[]){  
    TestMultiPriority1 m1=new TestMultiPriority1();  
    TestMultiPriority1 m2=new TestMultiPriority1();  
    m1.setPriority(Thread.MIN_PRIORITY);  
    m2.setPriority(Thread.MAX_PRIORITY);  
    m1.start();  
    m2.start();  
        
   }   
      }     


Output: 

       running thread name is:Thread-0
       running thread priority is:10
       running thread name is:Thread-1
       running thread priority is:1

No comments:

Post a Comment