CodesJava

Easy learning with example program codes

how to get current thread in java?


The currentThread() method of Thread class is used to get current thread in java. It is a static method.
Syntax of currentThread() method:

public static Thread currentThread()

It returns a reference to the currently running thread.

Get current thread example

package com.codesjava;
 
public class Test {
	public static void main(String args[]){
		Thread currentThread = Thread.currentThread();
		System.out.println(currentThread);
	}
}

Output

Thread[main,5,main]

Related Topics:

Please follow and like us:
Posted in Java   

Core Java Tutorial



Copyright © 2019 CodesJava DMCA.com Protection Status SiteMap Reference: Java Wiki