Analyzing Java Applications on the Fly with Arthas

Arthas created by Alibaba is a tool that allows developers to connect to running Java applications without stopping them or suspending threads for debugging the application from the console. It offers features like monitoring invocation statistics, searching for classes and methods in the classloaders, view method invocation details (like parameters), show the stack trace of a method invocation, monitor system metrics and others. In the following examples I’m going to demonstrate some of these features applied to a running web application. ...

October 31, 2018 · 8 min · 1525 words · Micha Kops

Analyzing Java Problems – Tools, Snippets and Workflows

When we need to investigate the cause for a dysfunctional Java application we have a plethora of tools available that on the one hand help us in gathering information, artifacts and statistics and on the other hand help us in processing this information and identifying possible problems. The following list of tools, snippets, workflows and information about specific artifacts could provide a starting point for analyzing such problems and covers topics like heap-dumps, thread-dumps, heap-histograms, heap-regions, garbage-collection-logs, hotspot-compiler/codecache-logs, debugging native-memory, tools for heap-dump-analysis, JVM unified logging and more.. ...

April 30, 2018 · 26 min · 5513 words · Micha Kops

Snippet: Java Mission Control (JMC) and Flight Recorder (JFR)

The Java Mission Control and the Java Flight Recorder allow us to capture run-time information from our Java applications without much overhead and aggregate profiling information. I have written down the commands that I’m using the most when profiling a Java application with this tool chain in the following article. Figure 1. Java Mission Control - Report Running Java Mission Control (JMC) We may start the JMC user interface shown above using the jmc command that is shipped with Oracle’s JRockit or Java (since Java 7 update 40). ...

October 11, 2017 · 4 min · 748 words · Micha Kops

Microbenchmarks with JMH / Java Microbenchmark Harness

Writing microbenchmarks for parts of our applications is not always easy – especially when the internals of the virtual machine, the just-in-time-compiler and such things are coming into effect. Java Microbenchmark Harness is a tool that takes care of creating JVM warmup-cycles, handling benchmark-input-parameters and running benchmarks as isolated processes etc. Now following a few short examples for writing microbenchmarks with JMH. Figure 1. Java JMH Microbenchmarks running in IntelliJ...

October 2, 2017 · 8 min · 1578 words · Micha Kops

Finding Memory Leaks using Eclipse and the MemoryAnalyzer Plugin

The MemoryAnalyzer Plugin for Eclipse allows us to quickly analyze heap dumps from a virtual machine and search for memory leaks. In the following tutorial we’re going to create and run a small application that is going to cause an OutOfMemoryException during its runtime. In addition, we’re forcing the virtual machine to save a heap dump and finally analyzing this data using Eclipse and the MemoryAnalyzer plugin. Prerequisites Java Development Kit 6 Eclipse Indigo ...

November 2, 2011 · 4 min · 704 words · Micha Kops

Kotlin Snippets

Checks / Exit Conditions Instead of writing something like if !condition throw …​ we may use require and check for quick exit conditions: val num = 1; require(num > 1){ // ... } val num = 1; require(num > 1){ // .. } Pluralize Strings Adding pluralization as extension function fun String.pluralize(count:Int):String { return if (count > 1){ this + 's' } else { this } } Use it like this ...

March 1, 2010 · 1 min · 160 words · Micha Kops

Maven Snippets

Extract Coordinates from the POM Helpful for build and integration environments, pipelines etc. Exctract the Project version from the pom.xml mvn org.apache.maven.plugins:maven-help-plugin:3.1.0:evaluate -Dexpression=project.version -q -DforceStdout Override a Property via local configuration e.g. to override the property xxx from your project’s pom.xml Create a directory .mvn in your project directory root Create a file named maven.config in this directory Insert -Dxxx=newvalue into the file to override this property Don’t forget to add .mvn to your .gitignore! ...

March 1, 2010 · 2 min · 401 words · Micha Kops

Misc Snippets

Data Normalizing Formula newVal = (oldVal-min) / (max-min) Ugly Scala Example package com.hascode import scala.collection.mutable.LinkedList object NormalizerExample extends App { val dataSet = LinkedList(1., 6.5, 3., 6.2, 20., 31.2, 50.2, 12., 0.24, 1.224, 2.2, 3.) for ((num, index) <- dataSet.zipWithIndex) { dataSet(index) = (num - dataSet.min) / (dataSet.max - dataSet.min) } println("Normalized: " + dataSet) } Normalized: LinkedList(0.01521216973578863, 0.12921819759798853, 0.05947594797769014, 0.12324029048767723, 0.3982240175619966, 0.6213992163469515, 1.0, 1.0, 0.07531115879828326, 0.40498283261802576, 0.7319742489270387, 1.0)

March 1, 2010 · 1 min · 69 words · Micha Kops