/*
 * $Id: ExThreadPool.java,v 1.3 2002/08/03 17:07:06 kredel Exp $
 */

//package edu.unima.ky.parallel;

import thread.ThreadPool;

/**
 * ExThreadPool
 * 
 * This program demonstartes the usage of Thread pools.
 * @author Akitoshi Yoshia
 * @author Heinz Kredel
 */

public class ExThreadPool {

    public static void main (String[] args) {
	ThreadPool pool = new ThreadPool();

	for (int i=0; i<10; i++) {
	    pool.addJob(new HardJob("job-"+i, 5));
	}
 
	pool.terminate();
    }
}

class HardJob implements Runnable {
    int delay;
    String name;

/**
 * Constructor
 * @param n name 
 * @param d delay 
 */
    public HardJob(String n, int d) {
	name = n;
	delay = d;
    }

/**
 * Returns the name
 */
    public String getName() {
	return name;
    }

/**
 * Causes the current thread to sleep
 */
    public void run() {
	System.out.println("Thread["+Thread.currentThread().getName()+
			   "] found "+name);
	try {
	    Thread.currentThread().sleep(delay*(long)(1000.0*Math.random()));
	}
	catch (InterruptedException e) {
	}
	System.out.println("Thread["+Thread.currentThread().getName()+
			   "] finished "+name);
    }

}
