synchronization level

  • method: synchronize aMethod() {}
  • statement: synchronize(anyObject) {}
  • Often using a lock on a method level is too coarse. Why lock up a piece of code that does not access any shared resources by locking up an entire method. Since each object has a lock, dummy objects can be created to implement block level synchronization. The block level is more efficient because it does not lock the whole method.