Mystery Jetty Threads Due To Failed Startup
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.
Create HTTPS Certificates in Java with Bouncy Castle
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.
Create HTTPS Certificates in Java: The unsafe way
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.
Secret SQL Weapon: Indexed (or Materialized) Views
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
Clojure defonce: Keep Your Apps State
One of the great strengths of Clojure is interactive development. Usually, you run a REPL and an editor that interacts with that REPL. You try out small things in the REPL, send pieces of code from the editor to the REPL, reload modified files, etc. You rarely restart the app, but keep going editing code. I’m missing that in other programming environments.
It works for Clojure due to many factors. The Lispy-ness with a distinct REPL at your disposal and tools taking advantage of it. Then the Clojure pushes you toward functional programming with immutable data structures, which then leads to a culture where the app state is usually held in very few places and the app mostly consists of functions operating on it. So when code is swapped the immutable state can be kept and be used with the new code.