package com.ygl;



public class TraditionThread {

public static void main(String[] args) {

//**************************************

Thread thread=new Thread(){

@Override

public void run() {



while(true)

try {

Thread.sleep(500);

System.out.println(Thread.currentThread().getName());

} catch (InterruptedException e) {

// TODO Auto-generated catch block

e.printStackTrace();

}


}





};

thread.start();

//**************************************


Thread thread2=new Thread(new Runnable(){



@Override

public void run() {



while(true)

try {

Thread.sleep(500);

System.out.println(Thread.currentThread().getName());

} catch (InterruptedException e) {

// TODO Auto-generated catch block

e.printStackTrace();

}


}



});



thread2.start();

//**************************************

new Thread(new Runnable(){

@Override

public void run() {

while(true)

try {

Thread.sleep(500);

System.out.println("Runnable"+Thread.currentThread().getName());

} catch (InterruptedException e) {

// TODO Auto-generated catch block

e.printStackTrace();

}


}


}){

//此处执行System.out.println("Thread"+Thread.currentThread().getName());

//而不会找System.out.println("Runnable"+Thread.currentThread().getName());因为被覆盖

public void run() {

while(true)

try {

Thread.sleep(500);

System.out.println("Thread"+Thread.currentThread().getName());

} catch (InterruptedException e) {

// TODO Auto-generated catch block

e.printStackTrace();

}







};

}.start();

}







}