Java Finally Killed Double-Checked Locking. The Code Proves It.
java
dev.to
Somewhere in the codebase you work on right now, there is almost certainly a field like this: private volatile ExpensiveClient client; public ExpensiveClient getClient() { ExpensiveClient c = client; if (c == null) { synchronized (this) { c = client; if (c == null) { client = c = ExpensiveClient.create(); } } } return c; } The double-checked locking idiom. You need the value to exist before the first ca