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