OpenJDK's Flight-Recorder and Mission Control

November 4, 2019

Flight Recorder is a low overhead profiler and diagnostics events recorder for the Hotspot JVM. Java Mission Control is a software to visualize these events. It has been included for years in the Oracle JDK but used to be a commercial feature. To use it you needed to add -XX:+UnlockCommercialFeatures -XX:+FlightRecorder flags and you were not allowed to use it in production unless you paid a license.

Oracle donated the code to the OpenJDK project and it is now included in OpenJDK 11 or newer builds. However, if you look at your JDK there is no Mission Control, so where it is? It is part of the OpenJDK but is built separately. You can download binaries from AdoptOpenJDK or Azul, which rebranded it as Zulu Mission Control.

Continue reading →

Mystery Jetty Threads Due To Failed Startup

October 30, 2019

Yesterday I had an app with an embedded Jetty Server which didn’t shut down properly. The main thread exited and the app had called .stop() on the Jetty server. However, the app kept running.

// App setup
// Then the app runs until the user stops it:
System.out.println("Press any key to stop");
while (System.in.available() <= 0) {
    Thread.sleep(1000);
}
jetty.stop();
System.out.println("Stopped");
// App doesn't quit here. It keeps running.
Continue reading →

Create HTTPS Certificates in Java with Bouncy Castle

October 29, 2019

Multiple times I needed to create HTTPS certificates programmatically. For example to create test certificates for HTTPS in development without complicated setup. There is surprisingly little information out there about how to create certificates programmatically in Java. Most guides OpenSSL or another command-line tool. I wanted to avoid to run an external program but wanted to do it programmatically.

In the past, I used a hacky way to do in Java by using JDK internals. However, as I moved to Java 11+ I needed a better way, since the API’s changed and are now inaccessible due to the module system.

Continue reading →

Create HTTPS Certificates in Java: The unsafe way

October 28, 2019

TLDR: I recommend using Bouncy Castle instead of this method. I used this method in the past but I’m using Bouncy Castle now to support Java 11+.

Multiple times I needed to create HTTPS certificates programmatically. For example to create test certificates for HTTPS in development without complicated setup. There is surprisingly little information out there about how to create certificates programmatically in Java. Most guides OpenSSL or another command-line tool. I wanted to avoid to run an external program but wanted to do it programmatically.

Continue reading →

Secret SQL Weapon: Indexed (or Materialized) Views

October 27, 2019

A few months backs I implemented logic which needs to lookup entries in a big existing table, but the lookup wasn’t easy indexable. Here’s a guide on one approach you can take. I’m using SQL Server for this example. Let’s assume we have a table with guests, something like this

CREATE TABLE Guests (
   Id BIGINT NOT NULL IDENTITY(1,1) PRIMARY KEY,
   Created datetime NOT NULL DEFAULT getutcdate(),
   Email VARCHAR(256) NOT NULL,
   Name VARCHAR(256) NOT NULL
   -- More fields
);

-- Example data
SELECT TOP (3) * FROM Guests
-- Result:
Id Created    Email  Name
1  2019-10-26 12:58:10.867    corrinne1981@rocketmail.com    Corrinne Bordons
2  2019-10-26 12:58:10.877    admin@schriever.us         Cythia Schriever
3  2019-10-26 12:58:11.177    darcie@tutanota.com            Darcie Potencio
Continue reading →