Blocking Java Thread Pool


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.
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.

I think the ThreadPoolExecutor is what you need:

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.
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?
>but was unable to see how to check when the last threads

When the last threads do what?
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?
You have the awaitTermination method,%20java.util.concurrent.TimeUnit%29 that blocks until all the threads are idle or the set timeout occurs. You also have afterExecute,%20java.lang.Throwable%29 that can set a method to be executed after every job termination (you can also check here some things).

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
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

From novice to tech pro — start learning today.