FileDocCategorySizeDatePackage
ThreadPool.javaAPI DocAndroid 1.5 API3163Wed May 06 22:41:06 BST 2009tests.support

ThreadPool

public class ThreadPool extends ThreadGroup

Fields Summary
private boolean
isAlive
private LinkedList
taskQueue
private int
threadID
private static int
threadPoolID
Constructors Summary
public ThreadPool(int numThreads)

        super("ThreadPool-" + (threadPoolID++));
        setDaemon(true);

        isAlive = true;

        taskQueue = new LinkedList<Runnable>();
        for (int i = 0; i < numThreads; i++) {
            new PooledThread().start();
        }
    
Methods Summary
public synchronized voidclose()

        if (isAlive) {
            isAlive = false;
            taskQueue.clear();
            interrupt();
        }
    
protected synchronized java.lang.RunnablegetTask()

        while (taskQueue.size() == 0) {
            if (!isAlive) {
                return null;
            }
            wait();
        }
        Logger.global.info("1 Task is removed");
        return (Runnable) taskQueue.removeFirst();
    
public voidjoin()

        synchronized (this) {
            isAlive = false;
            notifyAll();
        }

        Thread[] threads = new Thread[activeCount()];
        int count = enumerate(threads);
        for (int i = 0; i < count; i++) {
            try {
                threads[i].join();
            } catch (InterruptedException ex) {
                System.err.println(ex.getMessage());
            }
        }
    
public synchronized voidrunTask(java.lang.Runnable task)

        if (!isAlive) {
            throw new IllegalStateException();
        }
        if (task != null) {
            taskQueue.add(task);
            notify();
        }