Java Lock Optimization Techniques and Thread Safety Mechanisms
UseโLevel Lock Optimization
Reduce Lock Holding Time
Code that does not require synchronization should be kept outside the critical section so that the lock is released as quickly as possible.
Reduce Lock Granularity
The idea is to split a single physical lock into multiple logical locks, increasing parallelism and reducing contention. This is ...
Posted on Wed, 28 Oct 2026 16:21:48 +0000 by sethcox
Advanced Java Collections: Working with Maps and Utility Classes
Advanced Collection Framework
Understanding Map Collections
Map collections in Java have several distinctive characteristics:
They store data in key-value pairs, requiring both elements for each entry
Keys must be unique while values can be duplicated
Each key maps to exactly one value, creating a one-to-one relationship
The combined key-value ...
Posted on Mon, 19 Oct 2026 16:15:39 +0000 by rmurdo
Understanding a Hidden Loop in ConcurrentHashMap's computeIfAbsent Method
JDK Bug Analysis
This article discusses a subtle issue discovered in JDK 8 related to the computeIfAbsent method within ConcurrentHashMap.
Discovery Process
The issue came to light while reviewing changes in Apache Dubbo 2.7.7. A specific bug fix was noted:
JDK-8062841: Deadlock in ConcurrentHashMap.computeIfAbsent when keys have identical has ...
Posted on Thu, 15 Oct 2026 16:12:39 +0000 by k4pil
Implementing Thread-Safe HashMap Patterns in Multi-threaded Java Applications
1. Method-Level Isolation via Thread Confinement
A robust strategy involves confining the HashMap instance to the execution scope of a single thread. In typical web server architectures, such as those built on Tomcat, incoming requests trigger a chain of operations involving controllers and services. Within the service layer method, a developer ...
Posted on Wed, 30 Sep 2026 16:31:06 +0000 by Invincible
Understanding HashMap Internals in JDK: Storage, Hashing, and Expansion
HashMap is one of the most widely used collections in Java applications, primarily for storing key-value pairs with efficient lookup performance. To understand its inner workings, we explore how it manages data storage, resolves collisions, handles resizing, and why it is not thread-safe.
Class Hierarchy and Core Interfaces
HashMap implements s ...
Posted on Mon, 28 Sep 2026 16:21:18 +0000 by mrhinman
Grouping Anagrams Using Sorted Strings as HashMap Keys
---------------๐๐ LeetCode Problem 49: Group Anagrams ๐๐-------------------
In Java, arrays cannot be used directly as keys in a HashMap because their hashCode() method does not reflect the actual content. It is therefore recommended to use immutable objects such as strings as keys.
Approach 1: Use a Sorted String as the Key
โญ๏ธ Since two ...
Posted on Fri, 18 Sep 2026 16:20:45 +0000 by ckwall
Display Table and Minimum Frogs Algorithm Problems
Display Table
Given an array of orders where each element contains a customer name, table number, and food item, return a display table showing how many of each dish was ordered at each table.
The table should have "Table" as the first column header, followed by alphabetical sorted food item names. Each row represents a table with its ...
Posted on Sun, 06 Sep 2026 16:36:50 +0000 by joebarker99
Java HashMap Implementation and Mechanisms
HashMap Core Characteristics
HashMap implements key-value storage using hash tables, offering non-thread-safe operations. Both keys and values can be null, and entries are unordered. Pre-JDK 1.8, HashMap used array-chaining (linked lists) to resolve collisions. Since JDK 1.8, when bucket chains exceed 8 elements and the array size surpasses 64, ...
Posted on Fri, 04 Sep 2026 16:49:05 +0000 by kwstephenchan
Java Thread-Safe Collections: ConcurrentHashMap vs HashMap in Concurrent Environments
Overview of Java Thread-Safe Classes
Class Type
Characteristics
Description
Legacy Thread-Safe Classes
Uses synchronized for thread safety
Deprecated classes like Stack, Vector, Hashtable
Collections-Decorated Classes
Wrapper classes using synchronized
Thread-safe versions of standard collections
JUC Classes
Uses CAS and multiple loc ...
Posted on Tue, 18 Aug 2026 16:58:00 +0000 by Ali25m
Popular LeetCode Problems and Solutions
Two Sum
Given an array of integers nums and a target value target, find the indices of two numbers that add up to target. Return the indices as a pair.
Solution 1: Brute Force
class Solution {
public int[] twoSum(int[] nums, int target) {
for (int i = 0; i < nums.length; i++) {
for (int j = i + 1; j < nums.lengt ...
Posted on Wed, 05 Aug 2026 16:23:22 +0000 by Banacek