Java 创建线程有二种创建方案

package cn.com.secn.thead;
//第一种方案
class MyThead implements Runnable
{
	public void run()
	{
		for (int i = 1; i <= 10; i++)
		{
			System.out.println(Thread.activeCount() + "thread======>AAA");
		}
	}
}
//第二种方案
class MyThread2 extends Thread
{

	public void run()
	{
		for (int i = 1; i <= 10; i++)
		{
			System.out.println(Thread.activeCount() + "thread======BBB");
		}
	}

}

public class TheadMain
{
	public static void main(String[] args)
	{
		MyThead myThead = new MyThead();
		Thread thread = new Thread(myThead);
		MyThread2 thread2 = new MyThread2();
		thread.start();
		thread2.start();
	}
}

你可能感兴趣的:(Java)