Skip to main content
Active Object

Intent

The Active Object design pattern provides a safe and reliable way to implement asynchronous behavior in concurrent systems. It achieves this by encapsulating tasks within objects that have their own thread and message queue. This separation keeps the main thread responsive and avoids issues like direct thread manipulation or shared state access.


iluwatarAbout 2 minConcurrencyPerformance
Async Method Invocation

Intent

Asynchronous method invocation is a pattern where the calling thread
is not blocked while waiting results of tasks. The pattern provides parallel
processing of multiple independent tasks and retrieving the results via
callbacks or waiting until everything is done.


iluwatarAbout 3 minConcurrencyAsynchronousReactiveScalability
Balking

Intent

Balking Pattern is used to prevent an object from executing a certain code if it is in an incomplete or inappropriate state. If the state is not suitable for the action, the method call is ignored (or "balked").

Explanation

Real world example

There's a start-button in a washing machine to initiate the laundry washing. When the washing
machine is inactive the button works as expected, but if it's already washing the button does
nothing.


iluwatarAbout 3 minConcurrencyDecoupling
Commander

Intent

Used to handle all problems that can be encountered when doing distributed transactions.

Class diagram

Commander class diagram

Applicability

This pattern can be used when we need to make commits into 2 (or more) databases to complete transaction, which cannot be done atomically and can thereby create problems.


iluwatarLess than 1 minuteConcurrencyCloud distributed
Event-based Asynchronous

Intent

The Event-based Asynchronous Pattern makes available the advantages of multithreaded applications while hiding many
of the complex issues inherent in multithreaded design. Using a class that supports this pattern can allow you to:

  1. Perform time-consuming tasks, such as downloads and database operations, "in the background," without interrupting your application.
  2. Execute multiple operations simultaneously, receiving notifications when each completes.
  3. Wait for resources to become available without stopping ("hanging") your application.
  4. Communicate with pending asynchronous operations using the familiar events-and-delegates model.

iluwatarLess than 1 minuteConcurrencyReactive
Event Queue

Intent

The intent of the event queue design pattern, also known as message queues, is to decouple the relationship between the
sender and receiver of events within a system. By decoupling the two parties, they do not interact with the event queue
simultaneously. Essentially, the event queue handles and processes requests in an asynchronous manner, therefore, this
system can be described as a first in, first out design pattern model. Event Queue is a suitable pattern if there is a
resource with limited accessibility (i.e. Audio or Database), however, you need to provide access to all the requests
which seeks this resource. Upon accessing an event from the queue, the program also removes it from the queue.


iluwatarAbout 3 minConcurrencyGame programming
Guarded Suspension

Intent

Use Guarded suspension pattern to handle a situation when you want to execute a method on object which is not in a proper state.

Class diagram

Guarded Suspension diagram

Applicability

Use Guarded Suspension pattern when the developer knows that the method execution will be blocked for a finite period of time


iluwatarLess than 1 minuteConcurrencyDecoupling
Half-Sync/Half-Async

Intent

The Half-Sync/Half-Async pattern decouples synchronous I/O from
asynchronous I/O in a system to simplify concurrent programming effort without
degrading execution efficiency.

Class diagram

Half-Sync/Half-Async class diagram

iluwatarAbout 3 minConcurrencyPerformance
Leader/Followers

Intent

The Leader/Followers design pattern is a pattern used to coordinate a selection of 'workers'. It allows tasks to execute concurrently
with the Leader delegating tasks to the Follower threads for execution. It is a very common design pattern used in multithreaded
situations such as servers, and works to help prevent ambiguity around delegation of tasks.


iluwatarAbout 2 minConcurrencyPerformance
Lockable Object

Intent

The lockable object design pattern ensures that there is only one user using the target object. Compared to the built-in synchronization mechanisms such as using the synchronized keyword, this pattern can lock objects for an undetermined time and is not tied to the duration of the request.


iluwatarAbout 3 minConcurrencyPerformance