Singleton Pattern Variants and Blocking Queue Implementation
Singleton pattern is a standard approach that ensures a class has only one instance, preventing multiple instantiations.
Eager Initialization (Thread-Safe): The simplest singleton implementation where the instance is created when the class is loaded, ensuring thread safety.
public class Singleton {
private static Singleton instance = new Si ...
Posted on Sat, 07 Nov 2026 16:48:51 +0000 by deth4uall
Implementing a Service Container and Service Manager in C++
Service Container Implementation
This article demonstrates the implementation of a singleton service management system using C++.
Service Container Class Features:
Register singleton types (default constructor)
Register singleton types (interface and implementation with default constructor)
Register singleton types (with custom factory functio ...
Posted on Mon, 26 Oct 2026 16:12:12 +0000 by RGBlackmore
Understanding Thread-Safe Maps: ConcurrentHashMap vs Hashtable
Thread-Safe Map Implementations
When working with maps in multi-threaded environments, several thread-safe implementations are available:
Collections.synchronizedMap(Map) wrapper
Hashtable
ConcurrentHashMap
Among these, ConcurrentHashMap generally offers the best performance and concurrency characteristics.
Collections.synchronizedMap Impleme ...
Posted on Fri, 02 Oct 2026 16:32:09 +0000 by alant
:Thread-Safe State Sharing Between Controller Methods
When building web applications, controllers often need to maintain shared state across multiple request handlers. A common pattern involves tracking metrics or caching temporary data that multiple methods must access.
The Static Field Approach
Using a static field creates a single instance shared by all controller instances and threads. While s ...
Posted on Wed, 23 Sep 2026 16:32:01 +0000 by melsi
Thread Safety of Beans in Spring Framework
Thread safety in Spring beans depends on their scope. Spring supports multiple bean scopes, with Singleton and Prototype being the most commonly used.
By default, Spring beans are singletons, meaning a single instance exists per Spring IoC container. In contrast, prototype-scoped beans create a new instance each time they are requested from the ...
Posted on Fri, 11 Sep 2026 16:01:38 +0000 by SuperTini
Thread-Safe Singleton Pattern Implementation in C#
Singleton Class Implementation
Implement a singleton pattern with lazy initialization:
public class Singleton
{
private static Singleton _instance = null;
private Singleton()
{
Console.WriteLine("Created {0}", GetType().Name);
}
public static Singleton GetInstance()
{
if (_instance == null)
...
Posted on Wed, 09 Sep 2026 16:11:20 +0000 by The_Assistant
Understanding the Java volatile Keyword: Visibility and Reordering Prevention
The volatile keyword in Java serves as a lightweight synchronization mechanism. When a shared variable is declared as volatile, any thread reading that variable is guaranteed to see the most recent value written by another thread. This prevents stale data issues without incurring the higher overhead of context switching and thread blocking asso ...
Posted on Mon, 07 Sep 2026 16:38:57 +0000 by mailjol
Implementing the Singleton Design Pattern in C#
The Singleton pattern ensures that a class has only one instance in memory and provides a global access point to retrieve that instance.
Note: When creating a Console App project in Visual Studio, choose the correct template (e.g., "Console App (.NET Framework)" instead of ".NET Core") to avoid unexpected encoding issues. T ...
Posted on Sat, 01 Aug 2026 16:56:41 +0000 by billmasters
.NET Event Programming: Implementation Patterns, Thread Safety, and Memory Management
Basic Event Implementation
In the Observer pattern, a subject (publisher) defines an event, and observers (subscribers) register handlers for that event. When the subject triggers the event, all registered observers execute their handlers. A basic implementation follows this pattern:
public class Publisher
{
public event EventHandler<Cus ...
Posted on Thu, 09 Jul 2026 17:18:09 +0000 by kazuki
Thread Synchronization Mechanisms in iOS and Concurrency Pitfalls
When multiple threads access shared resources—such as the same object, variable, or file—data corruption and race conditions can easily occur. This fundamental concurrency problem is illustrated by classic examples like bank transactions and ticket selling.
Analyzing the Race Condition
Consider an accountBalance property modified by concurrent ...
Posted on Mon, 06 Jul 2026 16:21:12 +0000 by TobesC