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

Read Full Tutorial open_in_new
arrow_back Back to Tutorials