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 250 views
250 views asked May 18, 2018 by avibootz
1 answer 203 views
203 views asked Feb 6, 2018 by avibootz
1 answer 277 views
1 answer 220 views
220 views asked May 18, 2018 by avibootz
1 answer 153 views
153 views asked Jan 29, 2024 by avibootz
1 answer 178 views
178 views asked Oct 14, 2016 by avibootz
...