Executor and Executor Service Framework
In Java , a task is a unit of work. To accomplish the work done we need to create a new Thread every time. There is a performance overhead associated with starting a new thread, and each thread is also allocated some memory for its stack etc. In low level Java threading , we have to follow task execution policy , in which the thread to which task has been submitted will only execute the task. How does Executor Framework come over the task execution policy and improve performance ? Executor framework provides a way to decouple the task execution policy stages from submition and execution . Instead of starting a new thread for every task to execute concurrently, the task can be passed to a thread pool . As soon as the pool has any idle threads the task is assigned to one of them and executed. Internally the tasks are inserted into a Blocking Queue which the threads in the pool are dequeuing from. When a new task is inserted into the queue one of the idle threads will deque