I have a thread pool that I use to run a bunch of URLConnections simultaneously. The pool is structured like this:
1. A class called ThreadPool starts 10 instances of a thread class called WorkerThread.
2. Each WorkerThread accesses the same static instance of a third class called TaskQueue which puts tasks into a vector in a sychronized method. The WorkerThreads pull tasks out of the vector (if any are available).
3. A result of the tasks is that more tasks are put in the queue (for a while, depending on the situation).
I've been having problems with this program because, although it runs as intended, after running it many times the DOS prompt tends to lock up and occasionally my computer crashes. Perhaps a lot of stray threads are left running? What would be the best way to ensure that the threads in this pool are stopped and garbage collected when the frame is closed?
I read through the tutorials at sun but they seemed to apply to a different situation. Thread.stop() is deprecated but would it apply in this situation? I've seen people set thread instances to null on system.exit(). Is that any good?
Any other advice on thread pooling appreciated.
--Will Duty
wduty@radicalfringe.com
1. A class called ThreadPool starts 10 instances of a thread class called WorkerThread.
2. Each WorkerThread accesses the same static instance of a third class called TaskQueue which puts tasks into a vector in a sychronized method. The WorkerThreads pull tasks out of the vector (if any are available).
3. A result of the tasks is that more tasks are put in the queue (for a while, depending on the situation).
I've been having problems with this program because, although it runs as intended, after running it many times the DOS prompt tends to lock up and occasionally my computer crashes. Perhaps a lot of stray threads are left running? What would be the best way to ensure that the threads in this pool are stopped and garbage collected when the frame is closed?
I read through the tutorials at sun but they seemed to apply to a different situation. Thread.stop() is deprecated but would it apply in this situation? I've seen people set thread instances to null on system.exit(). Is that any good?
Any other advice on thread pooling appreciated.
--Will Duty
wduty@radicalfringe.com