java - Is collection synchronizing (via Collections.synchronizedX) necessary when access methods are synchronized? -
there lot of topics when synchronization in java appears. in many of them recommended using invokation of collections.synchronized{collecation, list, map, set, sortedmap, sortedset} instead of collection, list, etc. in case of multithreading work thread-safe access.
lets imagine situation when threads exist , of them need access collection via methods have synchronized block in bodies.
so then, necessary use:
collection collection = collections.synchronizedcollection(new arraylist<t>());
or only
collection collection = new arraylist<string>();
need to?
maybe can show me example when second attempt instead of first cause evidently incorrect behaviour?
to contrary, collections.synchronizedcollection()
not sufficient because many operations (like iterating, check add, etc.) need additional, explicit synchronization.
if every access collection done through synchronized methods, wrapping collection again syncronized proxy useless.
Comments
Post a Comment