Java-based thread blocking queue

Source: Internet
Author: User

The blocking queue is the content in the Java line assigns feature, Java defines a blocking queue interface Java.util.concurrent.BlockingQueue, the concept of a blocking queue is a queue of a specified length, if the queue is full, the addition of new elements will be blocked waiting until there is a vacancy. Similarly, when the queue is empty, the operation of the request queue element also blocks the wait until there are available elements

The blocking queue also has many implementation classes to meet a variety of complex requirements: Blockingqueue, Arrayblockingqueue, Delayqueue, Linkedblockingqueue, Priorityblockingqueue, Synchronousqueue

 PackageUnit_fifteen;ImportJava.util.concurrent.BlockingQueue;ImportJava.util.concurrent.ArrayBlockingQueue;/*** Java thread: New feature-blocking queue **/ Public classTest { Public Static voidMain (string[] args)throwsinterruptedexception {blockingqueue bqueue=NewArrayblockingqueue (20);  for(inti = 0; I < 30; i++) {            //adds the specified element to this queue, if there is no free space, waits (if necessary). bqueue.put (i); System.out.println ("added elements to the blocking queue:" +i); } System.out.println ("The program ends at this run and is about to exit----"); }}

Java-based thread blocking queue

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.