Skip to content

Modernize Java concurrency patterns: Java 8–17 updates + Java 21 doc stubs#12

Draft
Copilot wants to merge 2 commits intomasterfrom
copilot/update-java-concurrency-patterns
Draft

Modernize Java concurrency patterns: Java 8–17 updates + Java 21 doc stubs#12
Copilot wants to merge 2 commits intomasterfrom
copilot/update-java-concurrency-patterns

Conversation

Copy link
Copy Markdown

Copilot AI commented Apr 9, 2026

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 from 3.7.03.12.1; source/target raised from 1117

Phase 2 — Java 8–17 modernizations

File Change
ThreadSafeDateFormat.java ThreadLocal.withInitial() + immutable DateTimeFormatter (no ThreadLocal needed)
ThreadLocalConfinement.java ThreadLocal.withInitial() lambda form
ImmutableObject.java MyImmutableObject inner class → Java 16 record
EventKeeper.java EventJava 16 record (with defensive byte[] copy in compact constructor); switchJava 14 switch expression
UsingParallelStreams.java Collectors.toList()Stream.toList() (Java 16)
UsingConcurrentCollections.java New demo of Java 8 bulk ops: merge, compute, forEach(threshold,…), reduceValues, search

Phase 3 — Java 9 APIs

File Change
UsingReactiveStreams.java Full java.util.concurrent.Flow implementation: SubmissionPublisherPrintSubscriber (back-pressure with request(1)), DoublingProcessor pipeline, three demos
UsingCompletableFuture.java Added orTimeout() and completeOnTimeout() (Java 9) with runnable examples
UsingAtomics.java Added VarHandleCounter using MethodHandles.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.javaThread.ofVirtual(), newVirtualThreadPerTaskExecutor(), carrier threads, pinning, isVirtual()
  • UsingStructuredConcurrency.javaStructuredTaskScope.ShutdownOnFailure and ShutdownOnSuccess
  • UsingScopedValues.javaScopedValue vs ThreadLocal comparison table, nested rebinding, structured concurrency integration
  • UsingExecutors.java — added Javadoc for the planned newVirtualThreadPerTaskExecutor() method

Phase 5 — New pattern stubs (Java 21)

  • VirtualThreadProducerConsumer.java — how virtual threads simplify the producer-consumer pattern
  • StructuredTaskConvergence.javaStructuredTaskScope replacing CyclicBarrier with automatic cancellation
  • StructuredBackgroundTaskExecutor.java — structured concurrency comparison table vs BackgroundTaskExecutor

Phase 6 — README

  • Added Java version coverage table (Java 8 → Java 17 → Java 21 stubs)
  • All new features and patterns listed with links
  • Preamble updated to reflect Java 8–17 coverage

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants