I'm looking at code for the Java 8 fixed thread pool. Here's a small sample:
ExecutorService service = Executors.newFixedThreadPool(100);
try {
for (int i = 0; i < 10; ++i) {
service.submit(() -> "In another thread!");
}
} catch (Exception e) {
// Do nothing
} finally {
service.shutdown();
}
The question I have is (in two parts):
a. How many threads will the fixed thread pool object above create? 100? Or just 10?
b. How can I check how many threads have been created?
How many threads will the fixed thread pool object above create? 100? Or just 10?
It isn't specified. All that is specified is that there will never be more than 100.
How can I check how many threads have been created?
There is no API for that. You could get the total thread count before and after, but that could be fuzzy as Java has other reasons for creating threads.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With