Skip to content

feat(F16): Migrate to structured concurrency and ReentrantLock - #72

Merged
lekhrocks merged 2 commits into
mainfrom
feature/f16-structured-concurrency
Sep 6, 2026
Merged

lekhrocks merged 2 commits into
mainfrom
feature/f16-structured-concurrency

Conversation

@lekhrocks

Copy link
Copy Markdown
Owner

Summary

Migrates the codebase to structured concurrency and carrier-thread-safe locking as part of F16.

Changes

File Change
SnapshotExecutor.java synchronized -> ReentrantLock, unstructured virtual threads -> StructuredTaskScope.open(Joiner.allSuccessfulOrThrow())
SnapshotWorker.java Object lock params -> ReentrantLock, synchronized -> lock/try/finally/unlock
RegionalDataSourceFactory.java New ReentrantLock failoverLock, synchronized methods -> explicit lock
application.yml Added spring.threads.virtual.enabled: true
ADR-004 Updated to reflect completed migration
ARCHITECTURE_ANALYSIS.md F16 marked done

Why

  • synchronized blocks pin virtual threads to carrier threads, defeating the purpose of virtual threads
  • StructuredTaskScope replaces manual LinkedBlockingQueue + Thread.startVirtualThread() + Thread.join() with structured lifecycle and automatic failure propagation
  • spring.threads.virtual.enabled: true enables virtual threads for Tomcat HTTP request handling

Reactive path deferred

Virtual threads + structured concurrency deliver equivalent resource control to Project Reactor/WebFlux without the servlet->reactive ecosystem migration. Revisited if backpressure becomes a requirement.

- Replace all synchronized blocks with ReentrantLock across
  SnapshotExecutor, SnapshotWorker, and RegionalDataSourceFactory
  to prevent virtual thread carrier-thread pinning
- Adopt StructuredTaskScope for parallel snapshot chunk fan-out,
  replacing manual work-queue + Thread.startVirtualThread() pattern
- Enable spring.threads.virtual.enabled for Tomcat virtual threads
- Update ADR-004 to reflect completed migration
- Mark F16 complete in ARCHITECTURE_ANALYSIS.md
@lekhrocks lekhrocks self-assigned this Sep 6, 2026
@lekhrocks
lekhrocks merged commit 5e3b989 into main Sep 6, 2026
18 of 19 checks passed
@lekhrocks
lekhrocks deleted the feature/f16-structured-concurrency branch September 6, 2026 06:14
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.

1 participant