Home > Back-end >  In the 2020-10-31 s: in Java LinkedTransferQueue and SynchronousQueue will have what differentiation
In the 2020-10-31 s: in Java LinkedTransferQueue and SynchronousQueue will have what differentiation

Time:11-01

In the 2020-10-31 s: in Java LinkedTransferQueue and SynchronousQueue will have what differentiation? # # f greatly architects a daily topic

CodePudding user response:

Use SynchronousQueue will: thread A put add data to the queue, if there are no other threads to take to get the data, then thread A block, until the other threads access to data, in the same way if thread B to get the data from the queue is empty, is blocked, waiting for the thread to add data

Use put LinkedTransferQueue: LinkedTransferQueue, tryTransfer and transfer multiple items can be added, LinkedTransferQueue has the function of SynchronousQueue will but LinkedTransferQueue producers won't block
TryTransfer and transfer with put, tryTransfer and transfer can detect whether there is a thread waiting to get the data, data directly detected awakens the waiting thread to this thread and not in the queue
  • Related