Implmenting your own
thread pool from scratch is tricky. And from a quick look through your code, it looks like you are heading down the wrong path.
I would suggest looking at the java.util.concurrent Package (added in
Java 5). It has thread pools (called Executors) built right in. The
Package's Summary page has some basic documentation. And many of the API pages for the various classes, such as the
ThreadPoolExecutor class, also have some good documentation and examples.
With that API, you can create a series of Callables, wrap them in FutureTasks if needed, and put them into an Executor. The Callable interface is a lot like the Runnable interface, but it can return a result and throw exceptions that you get later when you go to get the results.
You might also want to look through the
Concurrency section of the Java Tutorial. It discusses multi-threading and the concurrency API.
Lastly, I can recommend the books
Java Concurrency in Practice {Addison-Wesley Professional, ISBN-10: 0-321-34960-1} and
Java Threads 3rd Edition {O'Reilly, ISBN-13: 978-0-596-00782-9}. Both are good books. The latter was co-authored by JavaRanch's own Henry Wong. Henry moderates the
Threads and Synchronization forum here at JavaRanch. So if you run into problems, post a question in that forum for some expert advice.
I hope that helps.
[ December 08, 2008: Message edited by: Mark Vedder ]