JavaRush /Java Blog /Random EN /ThreadPoolExecutor
Core
Level 35
Екатеринбург

ThreadPoolExecutor

Published in the Random EN group
Good afternoon. ThreadPoolExecutor - 1There is a question for an interview like this. How many ways to create threads do you know? The number 2 appears in the answers: either create Thread, passing it Runnable, or create an object of a descendant class Threadin which run(). But I wondered: is it two? If you use concurrent, for example, Executors.newFixedThreadPool(5)then when thread objects are created, immediately when this method is executed, or later, when tasks appear for execution (after all, they may not appear). All these factory methods return some kind of configuration ThreadPoolExecutor, which has one of the configuration parameters. corePoolSize About this field it is written: corePoolSize– the number of threads to keep in the pool, even if they are idle , unless allowCoreThreadTimeOutis set On the other hand, if the tasks didn’t arrive, then we created 5 workers idle, maybe they start being created when tasks start arriving? In general, 2 or 3 options can still be kept in mind as an answer to the question?
Comments
TO VIEW ALL COMMENTS OR TO MAKE A COMMENT,
GO TO FULL VERSION