Concurrency

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. Explanation Real world example Launching space rockets is an exciting business. The mission command gives an order to launch and after some undetermined time, the rocket either launches successfully or fails miserably.
Balking
Intent Balking Pattern is used to prevent an object from executing a certain code if it is in an incomplete or inappropriate state. 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. In plain words Using the balking pattern, a certain code executes only if the object is in particular state.
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.
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: Perform time-consuming tasks, such as downloads and database operations, “in the background,” without interrupting your application. Execute multiple operations simultaneously, receiving notifications when each completes. Wait for resources to become available without stopping (“hanging”) your application. Communicate with pending asynchronous operations using the familiar events-and-delegates model.
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 Applicability Use Guarded Suspension pattern when the developer knows that the method execution will be blocked for a finite period of time Related patterns Balking
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 Applicability Use Half-Sync/Half-Async pattern when a system possesses following characteristics: the system must perform tasks in response to external events that occur asynchronously, like hardware interrupts in OS it is inefficient to dedicate separate thread of control to perform synchronous I/O for each external source of event the higher level tasks in the system can be simplified significantly if I/O is performed synchronously.
Leader/Followers
Intent The Leader/Followers pattern provides a concurrency model where multiple threads can efficiently de-multiplex events and dispatch event handlers that process I/O handles shared by the threads. Class diagram Applicability Use Leader-Followers pattern when multiple threads take turns sharing a set of event sources in order to detect, de-multiplex, dispatch and process service requests that occur on the event sources. Real world examples ACE Thread Pool Reactor framework JAWS Real-time CORBA Credits Douglas C.
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. Explanation Real-world example The Sword Of Aragorn is a legendary object that only one creature can possess at the time. Every creature in the middle earth wants to possess is, so as long as it’s not locked, every creature will fight for it.
Master-Worker
Also known as Master-slave or Map-reduce Intent Used for centralised parallel processing. Class diagram Applicability This pattern can be used when data can be divided into multiple parts, all of which need to go through the same computation to give a result, which need to be aggregated to get the final result. Explanation In this pattern, parallel processing is performed using a system consisting of a master and some number of workers, where a master divides the work among the workers, gets the result back from them and assimilates all the results to give final result.