Thread-safe object groups and object pools

There are two places in the thread pool to ensure thread safety. 1. Single thread - only one thread can enter at a time. 2. The queue in the thread pool uses a blocking queue.

. The thread pool object is competed by multiple threads, and this object is used as the lock, that is, the realization of

 

Object pool: The objects in the queue in the single-threaded thread pool can only be accessed by one thread at a time

 

Object group: A number assembles many single-threaded pool objects, so that the objects in the array themselves are thread-safe, and the business objects are obtained from their queues (the business objects in the queue are not thread-safe), which can be understood as the object group is multiple Object pool into array

The array is for multi-threaded concurrency, and the single-threaded pool object in the array is to deal with the problem of operating an object at the same time in multi-threaded concurrency (put it in the task queue to wait) ---nioeventloop

 workers=array

worker = single thread pool object = nioeventloop,

nioeventloop=selectors+taskqueue

 Use channel as lock to prevent different threads (client, another client operating a channel at the same time)

 One selector and one channel (selecrors is a separate collection of all the pipeline registration events in a pipeline)

 

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326015520&siteId=291194637