其他分享
首页 > 其他分享> > 继承Thread类

继承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+"次运行");
		}
	}
	
}

标签:Thread,currentThread,继承,System,int,MyThread1,public
来源: https://blog.csdn.net/m0_46331585/article/details/120756800