Guidelines about threads

From Bruce Eckel’s Thinking in Java book, about threads:

  1. If you need to synchronize one method in a class, synchronize all of them. It’s often difficult to tell for sure if a method will be negativelyaffected if you leave synchronization out.
  2. Be extremely careful when removing synchronization from methods. The typical reason to do this is for performance, but in JDK 1.3 and 1.4 the overhead of synchronized has been greatly reduced. In addition, you should only do this after using a profiler to determine that synchronized is indeed the bottleneck.

2 Replies to “Guidelines about threads”

  1. “If you need to synchronize one method in a class, synchronize all of them.”
    Interesting advice, Bruce Eckel always giving us this useful tips, to me it would be obvious to do just the opposite πŸ™‚

  2. “If you need to synchronize one method in a class, synchronize all of them.”
    Interesting advice, Bruce Eckel always giving us this useful tips, to me it would be obvious to do just the opposite πŸ™‚

Leave a Reply

Your email address will not be published. Required fields are marked *