Overview of Stream Gatherers in JDK 25
Stream and remain lazy until a terminal operation is invoked.website·Indexed 29 days ago
https://vulinhjava.io.vnA technical blog focusing on Java development, Spring Boot, and JPA. Content covers JDK features from 8 through 21 and 25, thread safety strategies (synchronized, volatile, ReentrantLock), Project Lombok best practices, and performance optimization such as solving the N+1 query problem. It also provides guides on integrating KeyCloak, P6Spy, and OpenFeign with QueryDSL, as well as discussions on design patterns like Singleton and the use of Stream Gatherers (JEP 485).
Stream and remain lazy until a terminal operation is invoked.Handling time globally requires accounting for political and geographical anomalies. Key examples include:
Java is strictly pass-by-value. This means that when a method is called, a copy of the argument's value is passed to the method. This applies to both primitive types and object types:
LinkedHashMap extends HashMap and maintains a doubly-linked list running through all its entries. This allows it to remember the exact order in which keys were inserted while maintaining the same O(1) performance characteristics as a standard HashMap.null object will result in a NullPointerException. Additionally, with the introduction of value classes (Project Valhalla), synchronizing on value class instances will result in a compile error or an IdentityException at runtime because value classes do not have monitors.Object lock = null;
synchronized(lock) { // Throws NullPointerException
System.out.println("This will never print");
}.get() method, as it is not explicit about failure. Use orElseThrow() to either retrieve the value or throw a NoSuchElementException, or provide a custom exception supplier for better error reporting.// Basic usage: throws NoSuchElementException if empty
var user = findUser(id).orElseThrow();
// Premium usage: throws a specific custom exception
var user = findUser(id).orElseThrow(
() -> new UserNotFoundException("User ID not found: " + id)
);The most effective development workflow is a symbiosis of prompt engineering and core computer science knowledge. Use AI to accelerate the coding phase, but apply manual oversight for the following critical software engineering stages:
@OneToMany or @ManyToMany). When fetching a list of parent entities and iterating over their children, JPA executes one query to fetch the parents (the '1') and then one additional query for each parent to fetch its children (the 'N'). This leads to poor scalability and high database I/O latency as the number of parent records increases. If an entity has multiple lazy collections, the problem compounds (e.g., 1 + 2N queries).Java's HashMap uses an internal array of buckets to store key-value pairs. Depending on the number of items in a bucket, it switches storage strategies to maintain performance:
Depending on the requirements for lazy loading and thread safety, use the following guidelines for implementing the Singleton pattern in modern Java:
synchronized blocks and double-checked locking patterns, as they are largely considered historical curiosities and are prone to implementation errors.