👨‍💻
Software Engineering
Clean Code: Agile Software Craftsmanship
Clean Code: Agile Software Craftsmanship
  • Clean Code
  • 1: Clean Code
    • There Will Be Code
    • Bad Code
    • The Total Cost of Owning a Mess
    • Schools of Thought
    • We are Authors
    • The Boy Scout Rule
    • Prequel and Principles
    • Conclusion
  • 2: Meaningful Names
  • 3: Functions
  • 4: Comments
  • 5: Formatting
  • 6: Objects and Data Structures
  • 7: Error Handling
  • 8: Boundaries
  • 9: Unit tests
  • 10: Classes
  • 12: Emergence
  • 13: Concurrency
    • Why Concurrency?
    • Challenges
    • Concurrency Defense Principles
    • Know Your Library
    • Know Your Execution Models
    • Beware Dependencies between Synchronized Methods
    • Keep Synchronized Sections Small
    • Writing Correct Shut-Down Code is Hard
    • Testing Threaded Code
    • Conclusion
Powered by GitBook
On this page
  • More than one synchronized method on the same class?
  • Client-Based Locking
  • Server-Based Locking
  • Adapted Server
  1. 13: Concurrency

Beware Dependencies between Synchronized Methods

Dependencies between synchronized methods cause subtle bugs in concurrent code.

More than one synchronized method on the same class?

Your system may be written incorrectly.

Recommendation:

There will be times when this is not possible. If so, use the following techniques:

Client-Based Locking

Have the Client lock the server before calling the first method. Make sure the lock's extent includes code calling the last method.

Server-Based Locking

Within the Server create a method that locks the server, calls all the methods, and then unlocks. Have the client call this new method.

Adapted Server

Create an intermediary that performs the locking. This is an example of server-based locking where the original server cannot be changed.

PreviousKnow Your Execution ModelsNextKeep Synchronized Sections Small

Last updated 9 months ago