获取线程基本信息的方法——Thread.currentThread()

在线程中使用Thread.currentThread()方法获取线程的信息,信息包括,线程名,线程的优先级,线程组的名称。

public class TestThreadMethod {
   
	public static void main(String[] args) {
   
  	//------Thread.currentThread()------获取线程信息
  	Thread thread = Thread.currentThread();
  	//toString()得到的内容为:[线程名称,线程的优先级,线程组的名称]
  	System.out.println(thread);
  
  	//创建线程
 	 MyRunnable myRunnable = new MyRunnable();
  	Thread t1 = new Thread(myRunnable);
  	Thread t2 = new Thread(myRunnable);
  	Thread t3 = new Thread(myRunnable);
  	//启动线程
  	t1.start();
  	t2.start();
  	t3.start();
 	}
 }
class MyRunnable implements Runnable{
   
 	public void run() {
   
 	 Thread t = Thread.currentThread();
  	System.out.println(t);
 	}
}