Get and set the thread name
=================================================//File Name : thread_demo//------------------------------ ------------------------------------------------///Author : common//Interface Name: mythread//attribute://Method: Class Mythread_1 Implements runnable{//implements Runnable interface private String name;//public mythread_1 (String name) {//constructor method//super ();//this.name = name;//} @Overridepublic void Run () {//overwrite the Run () method in the Thread class//TODO auto-generated method stub for (int i=0;i<10;i++) {// System.out.println (name+ "Run, i=" +i); System.out.println (Thread.CurrentThread (). GetName () + ", i=" +i);//Remove the name of the current thread}}}//main class//function : Thread_ Demopublic class Runnable_demo {public static void main (string[] args) {mythread_1 mt1 = new Mythread_1 ();//Instantiate Runnable sub-class pair Like new Thread (MT1). Start ();//The system automatically sets the thread name new thread (MT1, "Thread A"). Start ();//manually set the thread name new thread (MT1, "thread B") automatically. Start (); Manually automatically set the thread name new thread (MT1). Start ();//The system automatically sets the thread name new thread (MT1). Start ();//system automatically sets the thread name}}
Java Thread action method