ConcurrentLinkedDeque vs LinkedBlockingDeque
By : Jackrin Patanasutaki
Date : March 29 2020, 07:55 AM
like below fixes the issue Two things: 1: If I were to use only the non-blocking methods in LinkedBlockingDeque such as addFirst() and removeFirst() does it have any difference to ConcurrentLinkedDeque? code :
public E removeFirst() {
E x = pollFirst();
..
}
public E pollFirst() {
lock.lock(); //Common lock for while list
try {
return unlinkFirst();
} finally {
lock.unlock();
}
}
|
Getting an element from a specific position from a ConcurrentLinkedDeque
By : user2102599
Date : March 29 2020, 07:55 AM
Any of those help ConcurrentLinkedDeque doesn't allow random access. you can only retrieve first or last element. though you can iterate over it. code :
ConcurrentLinkedDeque<Integer> dq = new ConcurrentLinkedDeque<>();
Iterator<Integer> itr = dq.iterator();
while (itr.hasNext()) {
Integer i = itr.next();
}
|
Java, ConcurrentLinkedDeque vs ConcurrentLinkedQueue - the difference?
By : user3103636
Date : March 29 2020, 07:55 AM
should help you out Both collections are thread-safe. The difference is that a ConcurrentLinkedDeque implements a Deque, which supports addition and removal of elements at both ends (e.g. addFirst and addLast), whereas ConcurrentLinkedQueue implements a Queue which allows insertion at one end called the tail of the queue and removal at the other end, called the head of the queue.
|
Can ConcurrentLinkedDeque have a fixed size and overwrite old elements?
By : TK3
Date : March 29 2020, 07:55 AM
With these it helps If I got this right ConcurrentLinkedDeque acts as a stack right if you use pollLast() ? , Can ConcurrentLinkedDeque have a fixed size?
|
Correct usage of ConcurrentLinkedDeque
By : user1614545
Date : March 29 2020, 07:55 AM
I hope this helps you . So, from the code you posted, it looks like what you're using charUsers for is just keeping track of everything that's in the current map. You're scanning through the collection to find entities, and you're adding and removing entities. And you're concerned about concurrent access to the collection? What about consistency, are you concerned about that? Like, thread A adds a thing, thread B removes it, and then thread A tries to act as though the thing is still in the collection; do you care? That's part of your concurrency problem. Now, a linked list is great if what you want is a list and you're going to be adding and removing nodes all the time and not necessarily at the ends. But a linked list is terrible if you want to search a collection for a specific item and you mostly don't care about all items at the same time. Maybe you want a map, after all -- ConcurrentHashMap, where the key is the thing's ID and the value is the thing. Every time you search for a thing, you're going to have to traverse that list until you find it, which winds up being an O(N) problem, right, and while you're traversing that list you are exposed to concurrent modification (maybe you want a CopyOnWriteArrayList, if you've got RAM to burn).
|