Java thread: new feature-blocking queue is the content of the new feature of Java 5 threads. java defines the interface for blocking queues Java. util. concurrent. blockingQueue: The concept of blocking queue is that a queue with a specified length will be blocked and wait until there is a blank space. Similarly, when the queue is empty, operations on the Request queue element will also block waiting until there are available elements. With this function, it opens a convenient channel for implementing the model of multi-thread queuing waiting, which is very useful. Java. util. concurrent. BlockingQueue inherits the java. util. Queue interface. For more information, see the API documentation. The following is an example of a simple application: import java. util. concurrent. blockingQueue; import java. util. concurrent. arrayBlockingQueue;/*** Java thread: new feature-blocking queue ** @ author leizhimin 14:59:15 */public class Test {public static void main (String [] args) throws InterruptedException {BlockingQueue bqueue = new ArrayBlockingQueue (20); for (int I = 0; I <30; I ++) {// Add the specified element to this queue, if there is no available space, it will remain waiting (if necessary ). Bqueue. put (I); System. out. println ("added element to the blocked queue:" + I);} System. out. println ("the program ends now and is about to exit ----") ;}} output result: element: 0 is added to the blocking queue: 1. An element is added to the blocking queue. 2. An element is added to the blocking queue. 3. An element is added to the blocking queue. 4. An element is added to the blocking queue: 5. added element to the blocking queue: 6. added element to the blocking queue: 7. added element to the blocking queue: 8. added element to the blocking queue: 9. An element is added to the blocking queue. element: 10 is added to the blocking queue. element: 11 is added to the blocking queue. element: 12 is added to the blocking queue: 13. element added to the blocking queue: 14. element added to the blocking queue: 15. element added to the blocking queue: 16. element added to the blocking queue: 17. added element to the blocking queue: 18 to the blocking queue: 19 As you can see, when the output is to element 19, it is always in the waiting state, because the queue is full and the program is blocked. Multithreading is not used for demonstration. This is not necessary. In addition, there are more implementation classes for blocking queues to meet various complex requirements: ArrayBlockingQueue, DelayQueue, LinkedBlockingQueue, PriorityBlockingQueue, and SynchronousQueue. The specific API differences are also small.