线程练习

版权声明:原创内容是本人学习总结,仅限学习使用,禁止用于其他用途。如有错误和不足,欢迎评论指正补充。 https://blog.csdn.net/qian_qian_123/article/details/82226569

使用线程的两种实现方式

public class MyThread1 extends Thread {
	private int count = 0;
	public void run() {
		while (count < 10) {
			System.out.println("我是继承Thread类的子类创建的线程" + count);
			count++;
		}
	}
}
public class MyThread2 implements Runnable {
	private int count = 0;
	public void run() {
		while (count < 10) {
			System.out.println("我是实现Runnable接口的子类创建的线程" + count);
			count++;
		}
	}
}
public class MyThreadTest {
	public static void main(String[] args) {
		MyThread1 t1=new MyThread1();//继承Thread的类
		Thread t2=new Thread(new MyThread2());//实现Runnable接口的类
	
		t2.start();
		t1.start();
	}
}

猜你喜欢

转载自blog.csdn.net/qian_qian_123/article/details/82226569
今日推荐