FileDocCategorySizeDatePackage
ThreadGroupDemo.javaAPI DocExample3491Sun Feb 08 21:34:08 GMT 2004None

ThreadGroupDemo

public class ThreadGroupDemo extends Object
Simple demo of ThreadGroup usage.

Fields Summary
Constructors Summary
Methods Summary
public static voidmain(java.lang.String[] args)

		new ThreadGroupDemo().work();
	
protected voidwork()

		ThreadGroup g = new MyThreadGroup("bulk threads");
		Runnable r = new Runnable() {
			public void run() {
				System.out.println(Thread.currentThread().getName() + " started");
				for (int i=0; i<5; i++) {
					System.out.println(Thread.currentThread().getName() + ": " + i);
					try {
						Thread.sleep(1776);
					} catch (InterruptedException ex) {
						System.out.println("Huh?");
					}
				}
			}
		};

		// Create and start all the Threads
		for (int i = 0; i< 10; i++) {
			new Thread(g, r).start();
		}

		// List them.
		Thread[] list = new Thread[g.activeCount()];
		g.enumerate(list);
		for (int i=0; i<list.length; i++) {
			if (list[i] == null)
				continue;
			Thread t = list[i];
			System.out.println(i + ": " + t);
		}