java c++ example - What are worker threads, and what is their role in the reactor pattern?




1 Answers

I assume you are talking about something like this documentation on thread-pools:

Most of the executor implementations in java.util.concurrent use thread pools, which consist of worker threads. This kind of thread exists separately from the Runnable and Callable tasks it executes and is often used to execute multiple tasks.

Worker threads are normal threads but they exist separate from the Runnable or Callable classes that they work on. If you extend Thread or you construct a Thread with a Runnable argument, the task is tied to the Thread object directly.

When you create a thread-pool using Executors.newFixedThreadPool(10); (or other similar methods), you create a pool of 10 threads that can run any number of different Runnable or Callable classes that are submitted to the pool. Underneath the covers they are still a Thread just more flexible because of the way they are wrapped.

In terms of the reactor pattern, different types of events are run by the handler threads which is similar. A thread is not tied to a single event class but will run any number of different events as they occur.

android design single

I'm trying to undertand the Reactor pattern (concurrent), but in many examples they are talking about 'worker threads'. What are worker threads? In what do they differ from 'normal' threads? And what is their role in the reactor pattern?




Related