java - Synchronize List vs synchronize object inside list -
lets have following list:
list<myobject> myobjectslist = new arraylist<>();
if this:
synchronized(myobjectslist ) { //some code runs here... }
does mean every object inside list thread safe or if other thread has reference of objects inside list can modify it?
... or if other thread has reference of objects inside list can modify it?
yes, can modify objects can acquire lock on myobject
instances.
Comments
Post a Comment