Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How should I manage multithreaded concurrent access to an ArrayDeque?

My Swing GUI displays a JList of items that are being sequentially removed by a background thread.

Behind the JList is an ArrayDeque<Card>, myHopper, implementing myHopper.getSize() and myHopper.getElementAt(), as per the contract of an AbstractListModel.

The background thread removes items using myHopper.poll().

Not surprisingly, I'm getting AWT array index out of bounds exceptions currently.

What should I be doing to properly synchronize access to myList between the EDT thread and my background thread? I have seen references to Collections.synchronizedList(arrayList) but I don't think that fits my ArrayDeque.

like image 512
Chap Avatar asked Nov 22 '25 05:11

Chap


1 Answers

Have you tried just using a LinkedBlockingDeque instead of the ArrayDeque?

like image 93
Maurício Linhares Avatar answered Nov 24 '25 18:11

Maurício Linhares



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!