Java线程的优先级从1到10级别,值越大优先级越高

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();
		thread.setPriority(Thread.MIN_PRIORITY);
		thread2.start();
		thread2.setPriority(Thread.MAX_PRIORITY);
	}
}

你可能感兴趣的:(Java线程的优先级从1到10级别,值越大优先级越高)