有三个线程ID分别是A、B、C,请有多线编程实现,在屏幕上循环打印10次ABCABC…...

package com.sgai;
/**
* 有三个线程ID分别是A、B、C,请有多线编程实现,在屏幕上循环打印10次ABCABC…
*
* @author 王俊磊
*
*/
public class TestThread extends Thread{
public void run(){
for (int i = 0; i < 10; i++) {
System.out.println(this.getName());
try {
Thread.currentThread().sleep(2000);
} catch (Exception e) {
e.printStackTrace();
}
}
}

public static void main(String[] args) {
TestThread a = new TestThread();
a.setName("A");
TestThread b = new TestThread();
b.setName("T");
TestThread c = new TestThread();
c.setName("C");
a.start();
b.start();
c.start();

}
}

你可能感兴趣的:(有三个线程ID分别是A、B、C,请有多线编程实现,在屏幕上循环打印10次ABCABC…...)