multithreading - Synconisized List/Map in Java if only one thread is writing to it -


the first thread filling collection continuously objects. second thread needs iterate on these objects, not change collection.

currently use collection.synchronized... making thread-safe there fast way doing it?

sorry not giving information context:

it's simple: first thread (ui) continuously writes mouse position arraylist, long mousebutton pressed down. second thread (render) draws line based on list.

even if synchronize list, it's not thread-safe while iterating on it, make sure synchronize on it:

synchronized(synchronizedlist) {     (object o : synchronizedlist) {         dosomething()     } } 

edit:

here's written article on matter: http://java67.blogspot.com/2014/12/how-to-synchronize-arraylist-in-java.html


Comments

Popular posts from this blog

mysql - FireDac error 314 - but DLLs are in program directory -

git - How to list all releases of public repository with GitHub API V3 -

c++ - Getting C2512 "no default constructor" for `ClassA` error on the first parentheses of constructor for `ClassB`? -