Newsletter sign-up
View all newsletters

Enterprise Java Newsletter
Stay up to date on the latest tutorials and Java community news posted on JavaWorld

JavaWorld Daily Brew

Check active worker thread to know how many threads are running



Hi,
I have written a worker thread class in order to run items in parallel. Since my machine have 8 cores of cpu, so I like to ALWAYS run 8-10 thread concurrently. At present, in a while loop, 10 threads are started and stored in a Vector, after that wait for all items (threads) in the vector to join. It's really bad habit!
Is there anyway to know how many worker threads are already running and utilize it to setup a thread-initializer method that guarantees 10 running threads?
Thanks.