4 Eylül 2018 Salı

ConcurrentLinkedQueue Sınıfı

Giriş
Açıklaması şöyle. LinkedList gibidir yani indeks kullanarak erişime izin vermez.
An unbounded thread-safe queue based on linked nodes. This queue orders elements FIFO (first-in-first-out). The head of the queue is that element that has been on the queue the longest time. The tail of the queue is that element that has been on the queue the shortest time. New elements are inserted at the tail of the queue, and the queue retrieval operations obtain elements at the head of the queue. A ConcurrentLinkedQueue is an appropriate choice when many threads will share access to a common collection. Like most other concurrent collection implementations, this class does not permit the use of null elements. This implementation employs an efficient "wait-free" algorithm based on one described in Simple, Fast, and Practical Non-Blocking and Blocking Concurrent Queue Algorithms by Maged M. Michael and Michael L. Scott.
constructor
Şöyle yaparız.
ConcurrentLinkedQueue<Integer> q=new ConcurrentLinkedQueue<Integer>();
add metodu
Şöyle yaparız.
int i=0;
q.add(i);
iterate metodu
Şöyle yaparız.
Queue<String> globalQueue = new ConcurrentLinkedQueue<String>();

//Multiple threads can safely call globalQueue.add()...

for (String href : globalQueue) {
    //do something with href
}
isEmpty metodu
Şöyle yaparız.
while(!q.isEmpty()){
  ...
}
remove metodu
Şöyle yaparız.
int value = q.remove();

Hiç yorum yok:

Yorum Gönder