• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 498
  • Last Modified:

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.
0
acilonv
Asked:
acilonv
  • 3
  • 2
1 Solution
 
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
Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

 
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
 
acilonvAuthor Commented:
no code provided
0

Featured Post

The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now