Thread currentThread() method in Java

Method delaration- public static native Thread currentThread().

Thread’s currentThread() is a static and native method which returns current executing thread. This method is native that means implementation has been written in some different language like c/c++. if you look into the source code, you will find no implementation logic in file. This method can be used to get current executing thread name.


Output is – Thread[main,5,main]

Let’s see another example where we will have two user-defined thread.

Output is –

Using Thread :- Thread-0
Using runnable :- Thread-1

Note – The output sequence can change. It depends on thread scheduler which thread it picks first.