Quick Refresh : Java : Executor Framework
Thread Pool and Executor Framework A thread pool reuses previously created threads to execute current tasks and offers a solution to the problem of thread life cycle overhead and resource thrashing. Since the thread is already existing when the request arrives, the delay introduced by thread creation is eliminated, making the application more responsive. Java provides the Executor framework which is centered around the Executor interface, its sub-interface – ExecutorService and the class- ThreadPoolExecutor , which implements both of these interfaces. By using the executor, one only has to implement the Runnable/Callable objects and send them to the executor to execute. They allow you to take advantage of threading, but focus on the tasks that you want the thread to perform, instead of thread mechanics. To use thread pools, we first create a object of ExecutorService and pass a set of tasks to it. ThreadPoolExecutor class allows to set the core and maximum pool size.The runnables t...