From the course: Advanced Java: Threads and Concurrency

Unlock the full course today

Join today to access over 23,200 courses taught by industry experts.

Worker threads and work stealing

Worker threads and work stealing - Java Tutorial

From the course: Advanced Java: Threads and Concurrency

Worker threads and work stealing

- [Instructor] Worker threads are nothing but Java threads that can perform tasks. The core of the Fork/Join framework is the Fork/Join pool, which is a thread pool of worker threads. Worker threads in the Fork/Join pool keep looking for tasks or subtasks to execute. So the idea behind a Fork/Join pool is to keep the worker threads as busy as possible. Each worker thread in the Fork/Join pool has a double-ended queue, which is known as a deque. This is where the tasks or more specifically subtasks are stored for the worker to work on. This is how it works. There's a Fork/Join pool with worker threads in it. The client task, let's say the main thread wants to submit tasks to this pool. The client first submits the task to a shared queue from where one of the worker threads in the pool would grab it from the queue. From this point onwards, everything will happen in the context of a Fork/Join task running in a Fork/Join pool. If a Fork/Join task that's run by a worker thread in the pool…

Contents