In this week’s collection, we have covered:
Java 24's JEP 491 update improves scalability by allowing virtual threads to release platform threads,
While Spring Framework 6.2 and Spring Boot 3.4 enhance container management and security.
The Mark-Scavenge garbage collection algorithm reduces inefficiencies in memory management, and
Other articles explore debugging Quarkus apps, improving testing with @MockBean, and building real-time notifications with Spring Boot and Redis.
Java 24 Stops Pinning Virtual Threads
JEP 491 improves Java's scalability by allowing virtual threads that block in synchronized methods to release their platform threads, making more threads available for other tasks.
This prevents virtual threads from being pinned to platform threads, a limitation that restricts scalability.
The update is included in Java 24 and JDK 24 EA builds. This video also explores remaining pinning cases, how to detect them, and touches on thread capture and io_uring.
Spring Framework 6.2 and Spring Boot 3.4 Improve Containers, and Actuators Ahead of New 2025 Generations
In November 2024, Broadcom released Spring Framework 6.2 and Spring Boot 3.4, both maintaining Java 17 and Jakarta EE 9 as their baselines.
Key features of Spring Boot 3.4 include structured logging, enhanced Docker Compose and Testcontainers support, and improved container image building, along with a more secure OCI image build process.
It also introduces new actuator endpoints and improves web server shutdown behavior.
Notable dependency upgrades include Spring Security 6.4, Hibernate 6.6, and Kafka 3.8.
Looking ahead, Spring Framework 7 and Spring Boot 4, planned for November 2025, will embrace Jakarta EE 11, JSpecify for null-safety, and Project Leyden for faster application startups.
Improving Garbage Collection Efficiency with the Mark-Scavenge Algorithm
The blog post introduces the Mark-Scavenge garbage collection algorithm, which addresses inefficiencies in traditional GC methods that use reachability as a proxy for object liveness.
This approach often results in unnecessary movement of dead objects, especially in moving collectors like ZGC and G1. Mark-Scavenge improves upon this by delaying object evacuation until the next GC cycle, allowing more objects to become unreachable and reducing wasted work.
Benchmark tests show that this approach can reduce the relocation of dead objects by up to 91%, leading to significant performance gains, particularly in memory-constrained environments or when allocation rates spike.
The algorithm offers improvements in latency and throughput, providing a more efficient solution to garbage collection in modern systems.
Debugging Quarkus Applications
The most effective way to debug a Quarkus app is using Quarkus Dev Mode, which enables additional features like live reload and continuous testing.
The tutorial also explores starting the app from the command line or directly from an IDE, along with remote development setups, such as deploying to OpenShift with live reload and debugging.
The article concludes that debugging in a containerized environment can help address environmental issues.
Reactive Real-Time Notifications with SSE, Spring Boot, and Redis Pub/Sub
A real-time notification system can be efficiently built using reactive technologies like Spring Boot Reactive, WebFlux, and Redis Pub/Sub.
By leveraging Server-Sent Events (SSE), a one-way communication channel, the system can push updates from the server to the client over a persistent HTTP connection, eliminating the need for client polling.
Spring Boot’s reactive model, based on non-blocking, asynchronous operations, allows handling a large number of concurrent requests with optimal resource utilization.
Redis Pub/Sub acts as a messaging broker, enabling real-time event distribution across various components.
This architecture offers scalability, responsiveness, and low-latency communication, making it suitable for use cases such as live notifications, dashboards, financial applications, and real-time tracking systems.
Nested Classes in Java: A Comprehensive Guide
Nested classes in Java are classes defined within other classes, promoting better organization and encapsulation of code.
There are four main types:
Inner Classes, which are tied to an instance of the outer class and can access its private members;
Static Nested Classes, which don’t have access to instance variables and are used for independent functionality;
Local Classes, defined within methods and accessible only within the method's scope, typically for one-time use; and
Anonymous Classes, which are unnamed and typically used for short-lived implementations, especially with interfaces or abstract classes.
Each type serves specific use cases, such as iterating over collections with inner classes (e.g.,
Iterator
inArrayList
) or using static nested classes as utility helpers, allowing for cleaner, more efficient code organization and encapsulation.
Hot Class Reload in Java: A Webpack HMR-Like Experience for Java Developers
Hot Class Reload (HCR) is a technique that enables developers to reload classes at runtime without needing to restart the entire application.
This allows for quicker iterations and a more seamless development experience, especially when making small changes to Java code.
HCR works by using Java's WatchService to monitor changes to source files, then dynamically compiling those files with the JavaCompiler API and reloading the updated classes via a custom class loader.
The process involves setting up directories for source and compiled classes, watching for changes to
.java
files, compiling them when changes are detected, and loading the new classes into the JVM.This workflow mimics the behavior of Hot Module Reload (HMR) in JavaScript, making the development process faster and more efficient. By reducing the time spent on restarts, developers can focus more on writing and testing code.
Crafting Your Own Railway Display with Java!
This project involves creating a personalized railway display using Java, SpringBoot, and Vaadin to display real-time train departure information from the Nederlandse Spoorwegen (NS) APIs on a Raspberry Pi 4.
The backend uses Jakarta WebTarget to fetch train data via NS’s Departures API, while the frontend utilizes Vaadin’s Grid component to display the data in a user-friendly format.
The system automatically updates every minute using Spring Boot's scheduling and Vaadin's Push functionality.
The project also includes hardware setup with Raspberry Pi, using SDKMAN for Java 17 installation and debugging through VSCode.
This project demonstrates how Java, SpringBoot, and Vaadin can work seamlessly together to create an efficient and visually appealing application for real-time data display.
Query JPA Single Table Inheritance
This article explains how to implement Single Table Inheritance (STI) in Java using the Java Persistence API (JPA) with Spring Boot. In STI, a class hierarchy is mapped to a single database table with a discriminator column to distinguish between different subclasses.
The example demonstrates how to create a Spring Boot project with a PostgreSQL database running in Docker, where the
Employee
superclass has two subclasses:FullTimeEmployee
andPartTimeEmployee
.Each subclass has unique attributes, and the discriminator column (
employee_type
) stores values likeFULL_TIME
andPART_TIME
. The article also covers setting up the database, defining entities, creating a repository, and querying for specific subtypes.The solution is tested via REST API endpoints, allowing querying by employee type. The article concludes that STI simplifies the database structure but may not be optimal for complex entities with many unique fields.
Configuring @MockBean Components Before Application Start
This article explains how to configure
@MockBean
components before the Spring Boot application starts for effective testing.@MockBean
allows for mocking Spring beans, which is useful for isolating components during integration tests, especially when interacting with external systems like databases or APIs.The article explores various techniques for early configuration, including direct declaration in the test class, using
@BeforeEach
, and employing nested or external test configuration classes to manage complex mocks.It also covers profile-specific configurations and dynamic mocks using Mockito’s
Answer
interface for flexible behavior during tests.The tutorial emphasizes best practices, such as limiting mock usage and verifying interactions, to ensure effective and controlled test environments.