How to get the ID of a thread in Java

1 Answer

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

class Program {
    public static void main(String[] args) {
        Thread thrd = new Thread(new MyThread());
        thrd.start();
    }
}


 
/*
run:
 
Thread ID: 10
 
*/

 



answered Jan 29, 2024 by avibootz

Related questions

1 answer 254 views
254 views asked May 18, 2018 by avibootz
1 answer 211 views
211 views asked Feb 6, 2018 by avibootz
1 answer 281 views
1 answer 224 views
224 views asked May 18, 2018 by avibootz
1 answer 156 views
156 views asked Jan 29, 2024 by avibootz
1 answer 182 views
182 views asked Oct 14, 2016 by avibootz
...