← Back to All Cheatsheets
Java Architecture

☕ Java 21 & Spring Boot 3 Architecture Reference

Modern Java 21 features including Virtual Threads (Project Loom), Record Patterns, and Spring Boot 3 configurations.

1. Virtual Threads (Project Loom Concurrency)

// Create a Virtual Thread Executor for million-scale concurrency
try (var executor = Executors.newVirtualThreadPerTaskExecutor()) {
    IntStream.range(0, 10_000).forEach(i -> {
        executor.submit(() -> {
            Thread.sleep(Duration.ofSeconds(1));
            return i;
        });
    });
}

2. Spring Boot 3 REST Controller Template

@RestController
@RequestMapping("/api/v1/users")
public class UserController {
    @GetMapping("/{id}")
    public ResponseEntity<UserDTO> getUserById(@PathVariable Long id) {
        return ResponseEntity.ok(userService.findById(id));
    }
}
Support My Work