Concurrent programming queue exploration

The queue has been used in the programming process, and it has been used more frequently recently. To summarize:

There are many ways to use it as a message queue, but there are different options for different scenarios.

Kafka: asynchronous processing, and partitioning can be achieved, which is more suitable for high concurrency distribution Type processing (easy to implement with automatic partitioning)
       Generation: Asynchronous writing \ Synchronous writing
       consumption: high-level api, easy to use; low-level api, you can freely control offset


BlockingQueue: blocking queue, this is generally used in the same process and is thread-safe Yes, multi-threading affects the generation efficiency
       : put\offer\add put will wait forever if the queue is full; offer supports incoming waiting time, and will return false after the waiting time; add will return abnormal
       consumption: remove\pull\take If it is empty, remove will return an exception; pull will return null; take will always wait.

        As can be seen from the above, when using queue, you must choose the appropriate api



Disruptor: lock-free according to the business scenario. Personally, it is very suitable for high-concurrency processing. The business is modified to fail fast or wait
           . On the basis of using cas, optimize

redis on the cpu cache: the choice of most scenarios, but it is used as a cache more, and less as a message queue



.

Guess you like

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