• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

synchronization query

 
Robert Benson
Ranch Hand
Posts: 56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I just want to nail down my understanding of synchronization, I've got two questions:


Q1/

Method A Synchronized
Method B (not marked as synchronized)
Method C (not marked as synchronized)

Methods B & C are in different classes


If method A is synchronized and method A calls B, which in turn calls C, does the whole chain become synchronized(A,B&C)?

My program does this, but B is only called by A. I assume this is safe and Synchronized?

Q2/ Is there a difference between the following. One uses Synchronization, the other locks. To me they both do the same thing, but example 1 is cleaner and less error prone:

e.g. 1


e.g. 2


Thanks, Robert.
 
Roel De Nijs
Sheriff
Posts: 10666
144
AngularJS Chrome Eclipse IDE Hibernate Java jQuery MySQL Database Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Robert,

Q1/ it depends. If method B (and C) are called from other methods than method A, methods B and C will not be synchronized.

Q2/ if you want to synchronize your complete method, then example 1 certainly does the job in the easiest way possible.

Kind regards,
Roel
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic