[Multithreading] LinkedTransferQueue

  • LinkedTransferQueue is JDK1.7 only add blocking queue based on linked list implementation of unbounded blocking FIFO queue is ConcurrentLinkedQueue (circulation CAS + wait-free concurrent algorithms volatile implemented) , SynchronousQueue (transmit elements fair mode) , LinkedBlockingQueue (obstruction of Queue the basic method) superset . And LinkedTransferQueue easier to use, because it not only combines several categories of functions, but also provides a more efficient implementation .

  • BlockingQueue interfaces , it refers to a queue: When a producer elements are added to the queue but the queue is full, the producer will be blocked; when consumers remove elements from the queue but the queue is empty, the consumer will be blocked .

  • LinkedTransferQueue using a pre-emption . Means that the consumer thread when taking element, if the queue is empty, it would generate a node (node element is null) into the team , then the consumer thread is waiting on this node , followed by the producer thread into the team found that when an element the node is null , the producer thread would not join the team , and directly on the filling element to the node , wake up the thread of the node waiting to be awakened consumer threads removed element is returned from the method call. That match is found, the node would not join the team, based on how the team could not find the parameter.

 

  • Use LinkedTransferQueue instead will make SynchronousQueue ThreadPoolExecutor give the corresponding performance .

  • Try to avoid using how == SYNC operation , because LinkedTransferQueue is unbounded queue , when a large number of threads are blocked, it will take a lot of thread resources .

Guess you like

Origin www.cnblogs.com/itplay/p/11121772.html