Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Buy a domain name - Register cheap domain names from $0.99 - Namecheap

Scalable Hosting That Grows With You

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Semrush - keyword research tool

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

39,870 questions

51,793 answers

573 users

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 157 views
157 views asked Jan 29, 2024 by avibootz
1 answer 161 views
161 views asked Oct 14, 2016 by avibootz
1 answer 156 views
1 answer 181 views
1 answer 160 views
160 views asked Feb 2, 2024 by avibootz
...