#26 JVM Tuning Using jcmd
Unleash the power of Java for shell scripting. Guide to SDKMAN! Functors, Applicatives, And Monads In Pictures. “Good Enough" Architecture.
Welcome to the twenty-sixth edition!
We often assume that productivity means getting more things done each day. Wrong. Productivity is getting important things done consistently.
– James Clear
A new JDK 16 Early Access Build is available. Remember that JDK 15 will be launched on September 15 and Oracle has prepared a virtual event: Oracle Developer Live—Java
JVM Tuning Using jcmd
When your application is running in a real environment you start having issues that were not discovered in your local or development environment.
How do you interact with the application to find how the application is behaving and find the source of your problems? One of the strengths of the JVM has been the number of tools available for diagnostics.
If the information provided by the monitoring and the application logs is not enough, we must enter into the server and use this type of utilities.
Some of these tools (jps, jmap, jstack...) that were considered experimental are converging into the jcmd command.
In “JVM Tuning Using jcmd” you can learn how to use jcmd to diagnose your problems: getting stack traces, memory histograms, heap dumps, GC logs, etc.
jcmd is a utility of a few kilobytes, distributed with the JDK. It’s just a frontend/client to the JVM, all the logic resides in the JVM.
The latest Java versions do not have Java Runtime Environment (JRE) as we know it. Thanks to JVM modularization you can create your custom JRE, and some distributions create it for you. Each distribution can include the command or not.
If you use a distribution or docker image that doesn’t include the jcmd executable and you add it to the path, it will not work. You need the JVM to be generated with the jcmd module.
Unleash the power of Java for shell scripting
If all you have is a hammer, everything looks like a nail
Python, Ruby, even JavaScript developers are used to writing shell scripts in their language. But in Java, this possibility, even if it was verbose and ugly, did not exist.
Until recently, because at the beginning of this year, Max Rydahl Andersen launched a project called jbang which solves this “problem”.
The utility allows you to execute Java code as scripts in your operating system (Linux, MacOS, and Windows), and goes beyond Running Single-file Programs without Compiling in Java 11.
You can create scripts without a Class and main method declaration (with jsh extension) or more complex code with multiple classes and methods. Using a special syntax, you can import dependencies from a maven repository.
If your bash script is too complex, probably this can be a solution… An unorthodox solution that the whole team knows is preferable to the technically correct solution that few people can modify.
You have all available information in the project home page in GitHub and Max gave a talk about jbang in DevNation.
As an example, Twilio team has written an article that uses Twilio API, Picoli and jbang: “How to build a CLI app in Java using jbang and picocli”.
Guide to SDKMAN!
I’ve mentioned SDKMAN in multiple dukesletter editions as a tool to manage multiple JDK installations, but the tool manages more stuff.
Its name comes from Software Development Kit Manager and can deal with the lifecycle of multiple types of utilities: Maven, Gradle, Leiningen, SBT (build tools), Grails, Micronaut (web frameworks), Scala, Kotlin, Groovy, Ceylon (languages)….
You have a complete guide in their site, but Baeldung has published an article explaining its usage managing installed JDKs and their integration with IntelliJ and Eclipse: “Guide to SDKMAN!”
Functors, Applicatives, And Monads In Pictures
When you enter the functional programming world you find a lot of terms in the literature. If you are not familiar with them, scare you.
To help us to understand them better, Aditya Bhargava published this article: “Functors, Applicatives, And Monads In Pictures”
The article was published in 2013, and I’ve seen its pictures in some presentations about functional programming. The code examples are written in Haskell, but are easily understandable for a Java person.
Over time the article has been translated to multiple human languages and to multiple programming languages. Java is not present, any volunteers?
“Good Enough" Architecture
Your system has an architecture whether you want it or not. There is no “good” or “bad” architecture without context; architecture needs to take specific quality attributes into account.
In the following talk Stefan Tilkov presents us with multiple cases, with their contexts, observations, and lessons learned:
For me, the key points of the talk are:
choose the simplest thing that will work
don’t build roadblocks
manage your system’s architectural evolution