Java Executors newCachedThreadPool() MethodThe newCachedThreadPool() method of Executors class creates a thread pool that creates new threads as needed but will reuse previously constructed threads when they are available. SyntaxParameterthreadFactory - the factory to use when creating new threads Returnsthe newly created thread pool ThrowsNullPointerException Example 1Test it NowOutput: size of mypool: 0 Total number threads scheduled): 2 Thread Name: pool-1-thread-2 Thread Name: pool-1-thread-1 after sleep Thread Name: pool-1-thread-2 after sleep Thread Name: pool-1-thread-1 Example 2Test it NowOutput: Thread Name: pool-1-thread-4 after sleep Thread Name: pool-1-thread-4 Thread Name: pool-1-thread-3 after sleep Thread Name: pool-1-thread-3 Thread Name: pool-1-thread-1 after sleep Thread Name: pool-1-thread-1 Next TopicJava Executors |
We provides tutorials and interview questions of all technology like java tutorial, android, java frameworks
G-13, 2nd Floor, Sec-3, Noida, UP, 201301, India