What is a worker thread and its difference from a thread which I create?

I am trying to explain the concept in a simple way, hope it will help to better understand the worker thread concept.

General Definition:-

A “worker thread” is just a thread which runs to perform some background work on the order of his boss(we can call it “client” ) and update work result to the client.

Technical Definition:-

A worker thread is usually defined as a thread that gets activated on clients’ requests.

Example 1:

1- We have a pizza store, where there are 10 guys who are experts in preparing a delicious pizza. These are called as “worker threads”.

2- We have a guy who receives orders from customers. That guy is called as “client”. Whenever a new order comes, one of “worker thread” starts preparing the pizza and updates to the client once the pizza is prepared.

3- When there are less than 10 orders, some of the workers just sit idle.

4- When there are more than 10 orders, the orders are just put into waiting queue.

Example 2:

1- There is an app server that listens to port 8080.

2- A request comes in on port 8080.

3- A listener thread (it’s called as “client”) takes that request and dispatches it to a “worker thread” that completes the request. There is actually a pool of “worker threads” maintained ( many objects of the “worker thread” program) on app server.

4- If two requests come in at the same time, two worker threads are assigned and the task is executed simultaneously.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)