Loading…
Loading…
Java
Modern concurrency on Java 25+ — platform and virtual threads, the scheduler, structured concurrency, scoped values, reactive comparisons, and how Spring Boot, Quarkus, Micronaut, Helidon and Jakarta EE adopt them. 50 articles with practice quizzes.
StructuredTaskScope subtasks inherit scoped-value bindings without copying, and forking under a different binding throws StructureViolationException. Use cases (depth guards, joining a unit of work, shrinking deadlines), a ThreadLocal migration checklist, and when to keep ThreadLocal.
kvi5hnuCode Sprout team member9 minThe Java 25 ScopedValue API: newInstance, where, run and call, get, isBound, orElse and orElseThrow. Dynamic scope, automatic rebinding in nested code, cleanup on exceptions, reusable carriers, null handling, and why plain threads don't inherit bindings.
kvi5hnuCode Sprout team member7 minWhy ThreadLocal is a poor carrier for context: any code can overwrite it, values outlive their task on pooled threads and leak between requests, and InheritableThreadLocal shares mutable objects, snapshots values at thread creation, and hands pool threads the wrong request's data.
kvi5hnuCode Sprout team member8 minRequest context such as a trace ID, tenant or currency must reach code deep in a call chain. Passing it as a parameter pollutes every signature; hiding it in a ThreadLocal cleans them up but adds hidden dependencies, nesting bugs and lost context across thread hand-offs.
kvi5hnuCode Sprout team member8 minStructured concurrency took seven previews to become final in Java 28. The class-based API of Java 21 to 24, the Joiner redesign of Java 25, the refinements in 26 and 27, and a migration checklist with the same trip quote written for Java 21, 25 and 27/28.
kvi5hnuCode Sprout team member8 minStructured concurrency makes the task tree visible. Name scopes with withName and subtask threads with a ThreadFactory, take JSON thread dumps with jcmd or HotSpotDiagnosticMXBean, read containers, parents and owners, and capture a dump automatically when an operation fails or stalls.
kvi5hnuCode Sprout team member7 minA subtask can open its own StructuredTaskScope, and the scopes form a tree. How failures travel up through nested join() calls, how cancellation and deadlines flow down through interrupts, unwrapping nested ExecutionException causes, and the nesting rules the API enforces.
kvi5hnuCode Sprout team member8 minThe happens-before guarantees of StructuredTaskScope: owner writes before fork() are visible to subtasks, and a subtask's writes are visible once its outcome is read or feeds join(). What isn't covered: sibling subtasks sharing state, writes after fork(), and losers' side effects.
kvi5hnuCode Sprout team member7 minImplement StructuredTaskScope.Joiner<T, R, R_X> for policies the built-ins don't cover: a quorum write that fails fast once success is impossible, a collector of every success and failure, and a best-offer joiner with a deadline. Which thread calls onFork, onComplete, result and timeout.
kvi5hnuCode Sprout team member8 minThe open(joiner, configOperator) overload in Java 27 and 28: naming a scope for thread dumps, naming subtask threads or running them on platform threads with a ThreadFactory, and withTimeout deadlines that start at open() and end in CancelledByTimeoutException or partial results.
kvi5hnuCode Sprout team member7 minHow failures travel out of a StructuredTaskScope in Java 27 and 28: ExecutionException and its cause, mapping causes with pattern matching, letting join() exceptions propagate, choosing an unchecked exception type, fallbacks inside subtasks, stack traces, and interrupts.
kvi5hnuCode Sprout team member8 minUse Joiner.anySuccessfulOrThrow to race equivalent subtasks: the first success wins, failures don't end the race, and the losers are cancelled. What happens when all fail or none were forked, and how to build a hedged request that asks a backup only when the primary is slow.
kvi5hnuCode Sprout team member6 minA Joiner decides when join() returns and what it gives back. The built-in joiners in Java 27 and 28: awaitAllSuccessfulOrThrow, allSuccessfulOrThrow returning a List, allUntil for collecting every outcome or stopping on your own condition, and custom exception types for join().
kvi5hnuCode Sprout team member8 minFork subtasks with Callable and Runnable, wait with join(), and read results through the Subtask handle: its UNAVAILABLE, SUCCESS and FAILED states, get() and exception(), what cancellation leaves behind, what an interrupted owner sees, and a fork() overload trap. A verified trip-quote demo.
kvi5hnuCode Sprout team member7 minThe idea behind structured concurrency: subtasks live inside the block that forked them. The lifecycle (open, fork, join, close), the owner thread, and the rules the API enforces with WrongThreadException, IllegalStateException and StructureViolationException, each shown in a demo.
kvi5hnuCode Sprout team member8 minWhy fanning out with ExecutorService and Future goes wrong when a subtask fails: orphaned siblings that keep running, failures noticed late because of the order of get() calls, interrupts that never reach subtasks, and thread dumps without task relationships. A demo and a first look at the fix.
kvi5hnuCode Sprout team member8 minA toy version of virtual threads in about 60 lines: a continuation per micro thread, a FIFO ForkJoinPool of carriers, a timer for sleep, and the yield-then-reschedule order that avoids a classic race. 10,000 micro threads on 2 carriers, and why real blocking calls had to be rewritten.
kvi5hnuCode Sprout team member7 minThe mechanism under every virtual thread: a continuation runs code until it yields, then resumes from the same point with its stack intact. Experiments with the JDK's internal Continuation class, a generator, freeze and lazy thaw with return barriers, and Java 21 pinning.
kvi5hnuCode Sprout team member8 minHow the JDK schedules virtual threads: a dedicated ForkJoinPool in FIFO async mode whose workers are the carriers, the parallelism and maxPoolSize settings, compensation for blocking calls, and the read and write pollers and delay scheduler that wake virtual threads up. Verified with jcmd on JDK 25.
kvi5hnuCode Sprout team member8 minWhy divide-and-conquer with nested futures starves a fixed thread pool, and how ForkJoinPool avoids it: fork, compute and join, workers that help instead of blocking, work stealing, RecursiveTask versus RecursiveAction, thresholds, the common pool, and the CAS operations that keep it lock-free.
kvi5hnuCode Sprout team member8 min