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

angular ui router - 10 digest iterations reached in angularjs when using $state.go -

symfony - InvalidConfigurationException in SecurityExtension.php line 429: No authentication listener registered for firewall "secured_area" -

javascript - Handling constructor related functions while testing with mocha and sinon -