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 246 views
246 views asked May 18, 2018 by avibootz
1 answer 192 views
192 views asked Feb 6, 2018 by avibootz
1 answer 266 views
1 answer 215 views
215 views asked May 18, 2018 by avibootz
1 answer 139 views
139 views asked Jan 29, 2024 by avibootz
1 answer 173 views
173 views asked Oct 14, 2016 by avibootz
...