阅读背景:

线程的基本操作3

来源:互联网 

线程组:   当线程数量较多,且功能比较明确时可以将类似的线程放到一起.

public class ThreadGroupName implements Runnable{

	@Override
	public void run() {
		Thread thread = Thread.currentThread();
		String name = thread.getThreadGroup().getName()+" :  "+thread.getName();
		while(true) {
			System.out.println("S9世界赛" + name);
			try {
				Thread.sleep(3000);
			} catch (InterruptedException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
	}
	
	public static void main(String[] args) {
		ThreadGroup group = new ThreadGroup("线程组");
		Thread thread1 = new  Thread(group, new ThreadGroupName(), "skt");
		Thread thread2 = new  Thread(group, new ThreadGroupName(), "fpx");
		thread1.start();
		thread2.start();
		System.out.println("活动的线程:"+group.activeCount()); //此为预估值,仅供参考
		group.list();
	}
}
publi



你的当前访问异常,请进行认证后继续阅读剩余内容。

分享到: