Modernize Java concurrency patterns: Java 8–17 updates + Java 21 doc stubs#12
Draft
Modernize Java concurrency patterns: Java 8–17 updates + Java 21 doc stubs#12
Conversation
…stubs Agent-Logs-Url: https://github.com/LeonardoZ/java-concurrency-patterns/sessions/7abdb29f-4b13-4d36-bc99-b156a7a2c01d Co-authored-by: LeonardoZ <3333540+LeonardoZ@users.noreply.github.com>
Agent-Logs-Url: https://github.com/LeonardoZ/java-concurrency-patterns/sessions/7abdb29f-4b13-4d36-bc99-b156a7a2c01d Co-authored-by: LeonardoZ <3333540+LeonardoZ@users.noreply.github.com>
Copilot created this pull request from a session on behalf of
LeonardoZ
April 9, 2026 14:14
View session
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Implements the modernization plan agreed in the previous session. The build target is raised to Java 17 (the highest version available in the current environment), with full working code for all Java 8–17 APIs and Javadoc-only stubs for Java 21 Project Loom features to serve as a migration guide.
All 53 source files compile cleanly (
mvn compile— BUILD SUCCESS).Changes by Phase
Phase 1 — Build configuration
pom.xml— compiler plugin bumped from3.7.0→3.12.1; source/target raised from11→17Phase 2 — Java 8–17 modernizations
ThreadSafeDateFormat.javaThreadLocal.withInitial()+ immutableDateTimeFormatter(noThreadLocalneeded)ThreadLocalConfinement.javaThreadLocal.withInitial()lambda formImmutableObject.javaMyImmutableObjectinner class → Java 16 recordEventKeeper.javaEvent→ Java 16 record (with defensivebyte[]copy in compact constructor);switch→ Java 14 switch expressionUsingParallelStreams.javaCollectors.toList()→Stream.toList()(Java 16)UsingConcurrentCollections.javamerge,compute,forEach(threshold,…),reduceValues,searchPhase 3 — Java 9 APIs
UsingReactiveStreams.javajava.util.concurrent.Flowimplementation:SubmissionPublisher→PrintSubscriber(back-pressure withrequest(1)),DoublingProcessorpipeline, three demosUsingCompletableFuture.javaorTimeout()andcompleteOnTimeout()(Java 9) with runnable examplesUsingAtomics.javaVarHandleCounterusingMethodHandles.lookup().findVarHandle(),getAndAdd,getVolatile,compareAndExchange(Java 9)Phase 4 — Java 21 documentation stubs
Files compile on Java 17 (no executable code). Each contains a detailed Javadoc description with runnable code examples in
{@code}blocks, ready to be activated when the project upgrades to JDK 21.UsingVirtualThreads.java—Thread.ofVirtual(),newVirtualThreadPerTaskExecutor(), carrier threads, pinning,isVirtual()UsingStructuredConcurrency.java—StructuredTaskScope.ShutdownOnFailureandShutdownOnSuccessUsingScopedValues.java—ScopedValuevsThreadLocalcomparison table, nested rebinding, structured concurrency integrationUsingExecutors.java— added Javadoc for the plannednewVirtualThreadPerTaskExecutor()methodPhase 5 — New pattern stubs (Java 21)
VirtualThreadProducerConsumer.java— how virtual threads simplify the producer-consumer patternStructuredTaskConvergence.java—StructuredTaskScopereplacingCyclicBarrierwith automatic cancellationStructuredBackgroundTaskExecutor.java— structured concurrency comparison table vsBackgroundTaskExecutorPhase 6 — README