Message Queue, Message Queue java

Source: Internet
Author: User

Message Queue, Message Queue java

When designing a message queue, we used double buffering to keep one read thread and one write thread !! The read thread operates on read_list and the write thread operates on write_list to keep the complete row of a queue!

For example, if you want to keep the write_list consistent, it is the cool of the insert operation. When the read_list is empty, it needs to be exchanged with the write_list. It also requires cool !! This ensures very few thread conflicts !!! At that time, the Message Queue Dual-buffering was designed using std: list!

The message queue of the second version has been greatly improved, using three buffer queues, one read queue, one write queue, and one Buffer Queue, the three queues are represented in arrays. As long as the consistency of the buffer queue is ensured, the cool is required when the write queue submits data to the buffer queue, read queues need to be shackled when they exchange data to the buffer queue! Compared with the above method, the number of shackles is significantly reduced, and the arrays are used, which is more efficient than std: list! This message queue is designed based on the original company's dual-Buffer Queue!

The test code is provided! And some interfaces!

+ View Code

Interface:

class DuplexList{ public:    DuplexList(int size = 1024);    virtual ~DuplexList(void);     virtual int append(CommonItem item);    virtual int peek(CommonItem &item); protected:    virtual int swap(CommonItem &item);    virtual int submit(); protected:    CommonList *read_list_;    CommonList *share_list_;    CommonList *write_list_;    Mutex _switch_mutex;    int peek_index_;};

After one afternoon of testing, there is no problem. It takes about 20 ms to transmit 10 million messages! This performance is fine!

I hesitated for a long time on the language selection. Some java friends advised me to say that a message queue error would cause the entire game to crash! Advise me to use the java integration structure !! However, I finally insisted on C ++. The underlying code was written in C ++ and the logic was written in lua! I just have a lot of questions about AI!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.