Blocking Java Thread Pool

Hello,

I'm looking for the simplest way to have in Java a pool of threads with the ability to specify the maximum number of threads, know at any given time how many threads are running and know when all the threads have finished running.

Thank you.
acilonvAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

miahiCommented:
I think the ThreadPoolExecutor is what you need: http://java.sun.com/j2se/1.5.0/docs/api/java/util/concurrent/ThreadPoolExecutor.html

You can set the maximum number of threads, get the number of executing threads, and you can set a method to be invoked when a thread ends, where you can check if it is the last one.
0
acilonvAuthor Commented:
I tried using the ThreadPoolExecutor class but was unable to see how to check when the last threads.
How do you do that?
0
VenabiliCommented:
>but was unable to see how to check when the last threads

When the last threads do what?
0
Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

acilonvAuthor Commented:
Oh, sorry. .... when it ends. How do I check when the last thread ends?
0
miahiCommented:
You have the awaitTermination method http://java.sun.com/j2se/1.5.0/docs/api/java/util/concurrent/ThreadPoolExecutor.html#awaitTermination%28long,%20java.util.concurrent.TimeUnit%29 that blocks until all the threads are idle or the set timeout occurs. You also have afterExecute http://java.sun.com/j2se/1.5.0/docs/api/java/util/concurrent/ThreadPoolExecutor.html#afterExecute%28java.lang.Runnable,%20java.lang.Throwable%29 that can set a method to be executed after every job termination (you can also check here some things).
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
acilonvAuthor Commented:
no code provided
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Java

From novice to tech pro — start learning today.