View Single Post
Old 11-06-2012, 07:13 PM   PM User | #4
Fou-Lu
God Emperor


 
Fou-Lu's Avatar
 
Join Date: Sep 2002
Location: Saskatoon, Saskatchewan
Posts: 15,653
Thanks: 4
Thanked 2,451 Times in 2,420 Posts
Fou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to all
Uh, no. The synchronized functionality in Java's purpose is to maintain integrity of an instance of an object, not multiple instances of an object. Multiple threads is of course the purpose, but when each of these threads has an instance of their own to work with, then there is no impact of using the synchronization functionality from one object into the next object. Synchronized can also be done on static methods as well as blocks (my preference if I run synchronized).
So in short, its purpose is to handle mutual access to a shared object. Give both instances of new B call the a1, and it will run as you expect. To implement shared handling on the class itself, you need to handle the threading at a higher level including using locks.
Fou-Lu is offline   Reply With Quote