Skip to content

refactor: harden ThreadForge task lifecycle - #4

Merged
wuuJiawei merged 17 commits into
mainfrom
feature/refactor-threadforge-lifecycle
Aug 10, 2026
Merged

wuuJiawei merged 17 commits into
mainfrom
feature/refactor-threadforge-lifecycle

Conversation

@wuuJiawei

Copy link
Copy Markdown
Owner

Summary

  • Isolate control timers from user scheduling work.
  • Make task lifecycle, cancellation, physical termination, and scope close deterministic.
  • Fix interruptible channels, completion-order fail-fast, await interruption, registration races, and context restoration.
  • Make scheduler and DelayScheduler shutdown behavior explicit.
  • Validate scheduling durations and retry multipliers.
  • Extend CI coverage to SLF4J, Micrometer, examples, and benchmarks.

Verification

  • Core: mvn -B -ntp clean verify and mvn -B -ntp clean install
  • SLF4J integration: mvn -B -ntp -f integrations/threadforge-slf4j/pom.xml clean verify
  • Micrometer integration: mvn -B -ntp -f integrations/threadforge-micrometer/pom.xml clean verify
  • Examples and benchmarks package successfully.
  • Core tests pass on JDK 8, 11, 17, and 21.

Please review; do not merge yet.

@wuuJiawei

Copy link
Copy Markdown
Owner Author

Verification update: concurrency and load testing

This PR has now been validated with repeated unit/integration tests, executable example scenarios, and sustained concurrent JMH load.

Unit and integration verification

Area Executions Result
Core full suite 617 tests x 4 runs = 2,468 PASS
SLF4J integration 4 tests x 10 runs = 40 PASS
Micrometer integration 1 test x 10 runs = 10 PASS
Lifecycle/race stress group 507 tests x 10 additional runs = 5,070 PASS
Example runtime scenarios 4 examples x 10 runs = 40 PASS

The lifecycle/race stress group covered:

  • SchedulerIsolationTest: 100 tests per run
  • TaskLifecycleTest: 107 tests per run
  • ScopeRegistrationRaceTest: 300 tests per run

Total JUnit executions across this verification pass: 7,588, with 0 failures, 0 errors, and 0 skipped tests.

All four examples were launched as real JVM processes. Their stdout was checked exactly on every run, and every process exited normally.

Concurrent JMH load

Environment: JDK 17.0.8, 10 logical CPUs, 32 GB RAM.

Scenario Concurrency Average time Approx. aggregate throughput
Fan-out / 8 child tasks 1 52.517 us/op 19.0k ops/s
Fan-out / 8 child tasks 8 332.335 us/op 24.1k ops/s
Fan-out / 8 child tasks 32 1.353 ms/op 23.7k ops/s
Fan-out / 8 child tasks 64 2.708 ms/op 23.6k ops/s
First-success / 3 candidates 1 34.485 us/op 29.0k ops/s
First-success / 3 candidates 8 138.155 us/op 57.9k ops/s
First-success / 3 candidates 32 566.802 us/op 56.5k ops/s
First-success / 3 candidates 64 1.143 ms/op 56.0k ops/s

The sustained 64-concurrency runs used 2 x 2-second warmups plus 5 x 5-second measurement windows:

  • Fan-out: approximately 590k scope operations and 4.72M child-task submissions during measured windows.
  • First-success: approximately 1.40M scope operations and 4.20M candidate-task submissions during measured windows.
  • No exceptions, deadlocks, permanent hangs, or resource-exhaustion failures were observed.

Performance observation

The structured lifecycle has measurable microbenchmark overhead versus the plain JDK baselines:

  • Fan-out: approximately 4-7x slower than ExecutorService/CompletableFuture baselines.
  • First-success: approximately 3-4x slower than ExecutorService.invokeAny.
  • Throughput on this 10-core host saturates around 8-32 concurrent benchmark workers.

This is not enough to call the change a performance regression because there is no same-host pre-fix baseline. It is recorded here as an optimization target and not hidden as a correctness failure.

Validation boundary

This is production-shaped local concurrency/load testing of the ThreadForge library, not replay of real production traffic. The repository does not contain a deployable HTTP service, production request model, or production endpoint.

Remote CI remains green on JDK 8, 11, 17, and 21, including integrations, examples, and benchmarks. git diff --check also passes.

@wuuJiawei
wuuJiawei merged commit 888b1d6 into main Aug 10, 2026
5 checks passed
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