The currentThread() method

The currentThread() method returns a reference to the currently executing thread object.

Syntax:


\begin{lstlisting}
public static Thread currentThread()
\end{lstlisting}

Example of currentThread() method


\begin{lstlisting}
class TestJoinMethod4 extends Thread{
public void run(){
...
...=new TestJoinMethod4();
\par
t1.start();
t2.start();
}
{
\end{lstlisting}

Test it Now


\begin{lstlisting}
Output:Thread-0
Thread-1
\end{lstlisting}