Skip to content

Commit 72eeb16

Browse files
committed
docs: add diagrams for lazy loading, leader election, leader followers, lockable object
1 parent d8b07ac commit 72eeb16

File tree

8 files changed

+16
-8
lines changed

8 files changed

+16
-8
lines changed

Diff for: lazy-loading/README.md

+4
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,10 @@ Wikipedia says
3535

3636
> Lazy loading (also known as asynchronous loading) is a technique used in computer programming, especially web design and web development, to defer initialization of an object until it is needed. It can contribute to efficiency in the program's operation if properly and appropriately used. This makes it ideal in use cases where network content is accessed and initialization times are to be kept at a minimum, such as in the case of web pages. For example, deferring loading of images on a web page until they are needed for viewing can make the initial display of the web page faster. The opposite of lazy loading is eager loading.
3737
38+
Sequence diagram
39+
40+
![Lazy Loading Sequence Diagram](./etc/lazy-loading-sequence-diagram.png)
41+
3842
## Programmatic Example of Lazy Loading Pattern in Java
3943

4044
The Lazy Loading design pattern is a performance optimization technique that delays the initialization of an object or a costly computation until it's absolutely necessary. This pattern can significantly improve the performance of your application by avoiding unnecessary computation and reducing memory usage.

Diff for: lazy-loading/etc/lazy-loading-sequence-diagram.png

55.9 KB
Loading

Diff for: leader-election/README.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,10 @@ Wikipedia says
3535

3636
> In distributed computing, leader election is the process of designating a single process as the organizer of some task distributed among several computers (nodes). Before the task has begun, all network nodes are either unaware which node will serve as the "leader" (or coordinator) of the task, or unable to communicate with the current coordinator. After a leader election algorithm has been run, however, each node throughout the network recognizes a particular, unique node as the task leader.
3737
38+
Sequence diagram
39+
40+
![Leader Election Sequence Diagram](./etc/leader-election-sequence-diagram.png)
41+
3842
## Programmatic Example of Leader Election Pattern in Java
3943

4044
The Leader Election pattern is a design approach that enables a distributed system to select one node as the coordinator or leader to manage tasks and maintain order, while other nodes operate as followers. This pattern is particularly useful in distributed systems where one node needs to act as a central coordinator for a specific function or decision-making process.
@@ -137,10 +141,6 @@ The `RingApp` class implements the Ring algorithm for leader election. In this a
137141

138142
These examples demonstrate how the Leader Election pattern can be implemented in different ways to suit the specific requirements of a distributed system.
139143

140-
## Detailed Explanation of Leader Election Pattern with Real-World Examples
141-
142-
![Leader Election](./etc/leader-election.urm.png "Leader Election pattern class diagram")
143-
144144
## When to Use the Leader Election Pattern in Java
145145

146146
Use the Leader Election pattern in Java applications where:
57.7 KB
Loading

Diff for: leader-followers/README.md

+4
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,10 @@ In plain words
2929

3030
> Select one server in the cluster as a leader. The leader is responsible for taking decisions on behalf of the entire cluster and propagating the decisions to all the other servers.
3131
32+
Sequence diagram
33+
34+
![Leader-Followers Sequence Diagram](./etc/leader-followers-sequence-diagram.png)
35+
3236
## Programmatic Example of Leader-Followers Pattern in Java
3337

3438
The Leader-Followers pattern is a concurrency design pattern where one thread (the leader) waits for work to arrive, de-multiplexes, dispatches, and processes the work, thereby enhancing CPU cache affinity and reducing event dispatching latency. Once the leader finishes processing the work, it promotes one of the follower threads to be the new leader. This pattern is useful for enhancing CPU cache affinity, minimizing locking overhead, and reducing event dispatching latency.
69 KB
Loading

Diff for: lockable-object/README.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,10 @@ Wikipedia says
3535

3636
> 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.
3737
38+
Sequence diagram
39+
40+
![Lockable Object Sequence Diagram](./etc/lockable-object-sequence-diagram.png)
41+
3842
## Programmatic Example of Lockable Object Pattern in Java
3943

4044
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 {
127131

128132
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.
129133

130-
## Detailed Explanation of Lockable Object Pattern with Real-World Examples
131-
132-
![Lockable Object](./etc/lockable-object.urm.png "Lockable Object class diagram")
133-
134134
## When to Use the Lockable Object Pattern in Java
135135

136136
* 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.
39 KB
Loading

0 commit comments

Comments
 (0)