The difference between Arrayblockingqueue and Linkedblockingqueue

Source: Internet
Author: User
Analyze the difference between arrayblockingqueue and Linkedblockingqueue, and draw the following conclusions:

1. The implementation of locks in the queue is different
Arrayblockingqueue implemented in the queue of the lock is not separated, that is, production and consumption is the same lock;
Linkedblockingqueue implementation of the lock in the queue is separate, that is, production is putlock, consumption is Takelock

2. Different operation during production or consumption
Arrayblockingqueue implementation of the queue in the production and consumption, is directly the enumeration object is inserted or removed;
Linkedblockingqueue implementation of the queue in the production and consumption, the need to convert the enumeration object to node<e> for insertion or removal, will affect performance

3. The queue size is initialized differently
The size of the queue must be specified in the Arrayblockingqueue implementation queue;
Linkedblockingqueue can not specify the size of the queue in the implemented queue, but the default is Integer.max_value

Attention:
1. When using the Linkedblockingqueue, if the default size and when the production speed is greater than the consumption speed, there may be memory overflow
2. When using Arrayblockingqueue and Linkedblockingqueue to queue 1 million simple characters respectively,
Linkedblockingqueue consumption is about 10 times times the consumption of Arrayblockingqueue,
That is, Linkedblockingqueue consumes about 1500 milliseconds, while Arrayblockingqueue only takes about 150 milliseconds

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.