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
Post a Comment