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

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 uniqInstance;

private Singleton() {
}

public static synchronized Singleton getInstance() {
if (uniqInstance == null) {
uniqInstance = new Singleton();
}
return uniqInstance;
}
public Object clone() throwsCloneNotSupportedException {
throw new CloneNotSupportedException();
}
// other useful methods here
}

 




1.3. Other Notes



A static class with static method would result in the same functionality as a singleton. As singletons are define using an object orientated approach it is in general advised to work with singletons.

Singleton violate the "One Class, one responsibility" principle as they are used to manage its one instance and the functionality of the class.

A singleton cannot be subclassed as the constructor is declared private.

Limitation : If you are using multiple classloaders then several instances of the singleton can get created.

FEW Popular Interview Questions:

[faqtaxlist type="singleton-designpattern"]

Popular posts from this blog

Chain of responsibility using Spring @Autowired List

Iterate Through a HashMap

Under the Hood: Understanding the Gossip Protocol in Apache Cassandra