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 File I/O

Java I/O is very interesting and much discussed feature of JAVA. There are few open-source library as well to make programmer's life easy. Here I will discuss only file reading example.

My favorite way to read a small file is to use a BufferedReader and a StringBuilder. It is very simple and to the point (though not particularly effective, but good enough for most cases):
    BufferedReader br = new BufferedReader(new FileReader("file.txt"));
try {
StringBuilder sb = new StringBuilder();
String line = br.readLine();

while (line != null) {
sb.append(line);
sb.append("n");
line = br.readLine();
}
String everything = sb.toString();
} finally {
br.close();
}

When I read strings like this, I usually want to do some string handling per line anyways, so then I go for this implementation.

One more way is to use the Scanner class in Java and the FileReader object simple exameple :
Scanner in = new Scanner(new FileReader("filename.txt"));

Scanner has several methods for reading in strings, numbers, etc... You can look for more info on this on the Java documentation page.

Though if I want to actually just read a file into a String I always use Apache Common IO with the class IOUtils.toString() method. You can have a look at the source here:

FileInputStream inputStream = new FileInputStream("foo.txt");
try {
String everything = IOUtils.toString(inputStream);
}
finally {
inputStream.close();
}

Below two links can be referred for more information on methods and examples.

http://commons.apache.org/io/description.html

http://download.oracle.com/javase/tutorial/essential/io/file.html

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