docs: add diagrams for lazy loading, leader election, leader followers, lockable object

This commit is contained in:
Ilkka Seppälä
2025-04-06 21:22:32 +03:00
parent d8b07ac484
commit 72eeb167c5
8 changed files with 16 additions and 8 deletions
+4 -4
View File
@@ -35,6 +35,10 @@ Wikipedia says
> In computer science, a lock or mutex (from mutual exclusion) is a synchronization primitive that prevents state from being modified or accessed by multiple threads of execution at once. Locks enforce mutual exclusion concurrency control policies, and with a variety of possible methods there exist multiple unique implementations for different applications.
Sequence diagram
![Lockable Object Sequence Diagram](./etc/lockable-object-sequence-diagram.png)
## Programmatic Example of Lockable Object Pattern in Java
The Lockable Object pattern is a concurrency control design pattern in Java that allows only one thread to access a shared resource at a time, ensuring mutual exclusion and preventing data corruption. Instead of using the `synchronized` keyword on the methods to be synchronized, the object which implements the Lockable interface handles the request.
@@ -127,10 +131,6 @@ public class App implements Runnable {
This example demonstrates the Lockable Object pattern by showing how multiple threads can attempt to acquire a lock on a shared resource, with only one thread being able to acquire the lock at a time.
## Detailed Explanation of Lockable Object Pattern with Real-World Examples
![Lockable Object](./etc/lockable-object.urm.png "Lockable Object class diagram")
## When to Use the Lockable Object Pattern in Java
* Use the Lockable Object pattern in Java when you need to prevent data corruption by multiple threads accessing a shared resource concurrently, ensuring thread safety and robust shared resource management.
Binary file not shown.

After

Width:  |  Height:  |  Size: 39 KiB