How to get thread priority in Java

1 Answer

0 votes
class MyThread implements Runnable {
    public void run() {
        try {
            System.out.println("Thread ID:" + Thread.currentThread().getId());
        } catch (Exception e) {
            System.out.println("Exception: " + e);
        }
    }
}

public class Program {
    public static void main(String[] args) {
        Thread trd1 = new Thread(new MyThread());
        Thread trd2 = new Thread(new MyThread());
        Thread trd3 = new Thread(new MyThread());

        System.out.println("Thread Priority: " + trd1.getPriority());
        System.out.println("Thread Priority: " + trd2.getPriority());
        System.out.println("Thread Priority: " + trd3.getPriority());

        trd1.start();
        trd2.start();
        trd3.start();
  }
}
 
 
 
  
/*
run:
  
Thread Priority: 5
Thread Priority: 5
Thread Priority: 5
Thread ID:16
Thread ID:17
Thread ID:15
  
*/

 



answered Jan 29, 2024 by avibootz

Related questions

1 answer 183 views
183 views asked Jan 29, 2024 by avibootz
1 answer 183 views
183 views asked Oct 14, 2016 by avibootz
1 answer 216 views
1 answer 241 views
1 answer 207 views
207 views asked Feb 2, 2024 by avibootz
...