继承Thread类

/**
 * 继承Thread类的线程
 * @author LYWZL
 *
 */
public class ThreadTest {
	public static void main(String[] args) {
		MyThread1 mtd = new MyThread1();
		mtd.start();
		Thread.currentThread().setName("我是主线程");
		for (int i = 0; i < 50; i++) {
			System.out.println(Thread.currentThread().getName()+"第"+i+"次运行");
		}
}

}
class MyThread1 extends Thread{
	@Override
	public void run() {
		Thread.currentThread().setName("我是子线程");
		for (int i = 0; i < 50; i++) {
			System.out.println(Thread.currentThread().getName()+"第"+i+"次运行");
		}
	}
	
}

上一篇:Semaphore信号量的使用


下一篇:【PAT甲级 map的使用】1035 Password (20 分)