farm ostrich
farm ostrich

Reputation: 5959

Java -- What is the most efficient way to synchronize an ArrayList?

My program has an openGL rendering thread and a data modification thread. The rendering thread accesses the data in a gaggle of ArrayLists, while the data modification thread alters, removes, and adds objects to the ArrayLists. The threads update about 60 times per second, and the ArrayList manipuation is the program's bottleneck. I've tried synch blocks (super slow), CopyOnWriteArrayLists (quite slow), and creating buffer ArrayLists in the rendering thread (lesser of three evils). What's the 'best' way to get maximum efficiency out of concurrent ArrayLists?

Upvotes: 5

Views: 593

Answers (2)

Chris Dennett
Chris Dennett

Reputation: 22721

The best mechanism is to do your work in the GL thread and queue operations to be executed. If there is only ever one thread accessing the list, there is no problem.

Upvotes: 1

Marcos Vasconcelos
Marcos Vasconcelos

Reputation: 18276

List<YourObject> syncList = Collections.synchronizedList(yourList);

Upvotes: 3

Related Questions