How Threadpool re-use Threads and how it works

后端 未结 4 1560
清酒与你
清酒与你 2020-11-30 03:17

My multithreading concepts are weak and trying to learn.

In Java what I know is, we can\'t call a thread more than once:

Thread t = new Thread; //So         


        
4条回答
  •  臣服心动
    2020-11-30 03:27

    The process workes in two parts:

    Submission of task: Thread pools are tightly coupled with a blocking Queue. When we say executor.execute(runnable). The runnable/callable is enqued in the queue.

    Execution of tasks: Now the tasks need to be picked up from the queue. Lets say whenever a task is submitted in the queue, it must be picked up and executed.

    So there are threads which will be running infinite loop and watching the queue for tasks. As soon as the tasks are available one thread will pick it and execute.

提交回复
热议问题