I’m at the moment looking to make a thread-safe program that allows me to implement a time-priority in my program. I’m happy to share code with you if you’d like, but that’s not really important to my question I don’t think. I originally used a linked list when I was working on getting a (non-thread safe) version of this program up and running, but now that I’m switching to a thread-safe version, I’ve changed from a linked list to a concurrent linked queue. The issue is that I need to get elements from the queue (usually from the head, occasionally from the tail). I really just need to see if the element at the head satisfies a certain property. In the linked list version it looked something like:
if (order.getQuantity()>= a.getFirst().getQuantity()){
Fill orderfill = new Fill(a.getFirst().getQuantity(),a.getFirst().getLimitPrice(), order.getOrderID(),a.getFirst().getOrderID());
fills.add(orderfill);
order.setQuantity(order.getQuantity()-a.getFirst().getQuantity());
a.removeFirst();
where here “a” is my linked list. When I change to concurrent linked queue, the getFirst method isn’t there anymore. Is there a method that is queue-friendly that accomplishes the same goals as the getFirst or getLast methods of linked list? (As you can see, I only need to get the object so that I can start using methods relevant to that object for something else).
Thank you so much!
You may want to use ConcurrentLinkedDeque, it offers
getFirst()andgetLast()methods.