Posts

Showing posts with the label Singleton

Observability Done Right: Best Practices and Anti-Patterns for Effective System Monitoring

Image
  WHAT Observability is a concept that refers to the ability to gain insights into the behavior and performance of complex systems. In the context of software engineering, observability involves the collection, analysis, and visualization of data from software applications, infrastructure, and other components of a system. In the animal kingdom, observability plays a critical role in survival, allowing animals to monitor their surroundings, detect threats, and find food. Dolphins use echolocation to observe their surroundings. They emit high-frequency sounds that bounce off objects, allowing them to create a 3D map of their environment. Thanks for reading Knowledge Cafe! Subscribe for free to receive new posts and support my work. Subscribed WHY In today's era, architectures are becoming increasingly large, complex, and fast-paced due to the faster development and deployment of software by distributed teams with the help of DevOps, continuous delivery, and agile development methodo...

Singleton Collection Classes

Image
Singletons are useful to provide a unique source of data or functionality to other Java Objects. Collection framework provides singleton classes for each collection class like SingletonList and SingletonMap.   In this article we will discuss about SingletonList which is equally applicable to other singleton collection classes. Collections Class provide method to convert normal list into singletonList like below syntax, List<String> mySingletonList = Collections. singletonList ( "AAA" ); Java documentation says "Returns an immutable list containing only the specified object. The returned list is serializable." Why we need this type single object Immutable list? Below is the code to remove all null values from list - in conventional style: package singleton; import java.util.ArrayList; import java.util.Collections; import java.util.List; public class SingletonListTest { public static void main (String[] args) { List ...

Java Singleton Design Pattern

1.1. Overview A singleton in Java is a class for which only one instance can be created provides a global point of access this instance. The singleton pattern describe how this can be archived. Singletons are useful to provide a unique source of data or functionality to other Java Objects. For example you may use a singleton to access your data model from within your application or to define logger which the rest of the application can use. 1.2. Code Example The possible implementation of Java depends on the version of Java you are using. As of Java 6 you can singletons with a single-element enum type. This way is currently the best way to implement a singleton in Java 1.6 or later according to tht book ""Effective Java from Joshua Bloch. package mypackage; public enum MyEnumSingleton { INSTANCE; // other useful methods here }   Before Java 1.6 a class which should be a singleton can be defined like the following. public class Singleton { private static Singleton uniqIn...