Java Executors newFixedThreadPool() MethodThe newFixedThreadPool() method of Executors class creates a thread pool that reuses a fixed number of threads operating off a shared unbounded queue. At any point, at most n Threads will be active processing tasks. If additional tasks are submitted when all threads are active, they will wait in the queue until a thread is available. SyntaxParameternThreads - the number of threads in the pool threadFactory - the factory to use when creating new threads ReturnsThrowsIllegalArgumentException NullPointerException Example 1Test it NowOutput: size of mypool: 0 Thread Name: pool-1-thread-1 after sleep Thread Name: pool-1-thread-1 Example 2Test it NowOutput: size of mypool: 0 Thread Name: pool-1-thread-1 after sleep Thread Name: pool-1-thread-1
Next TopicJava Executors
|