Reputation: 456
I created a threadpool with the value of 5. After assigning the tasks to 5 threads, the worker should wait to create the thread until a thread get free in Threadpool. So, how to find, is any thread is free in a threadpool?
Thanks in advance....
Upvotes: 1
Views: 1603
Reputation: 19622
if (thread instanceof ThreadPoolExecutor) {
System.out.println(
"Pool size is now " +
((ThreadPoolExecutor) pool).getActiveCount()
);
}
Taking into Consideration that the name of the ExecutorService is thread, this provides you the active thread and now you can get the free threads.
Upvotes: 2