Skip to content

Tascalate Concurrent 1.0.0

Choose a tag to compare

@vsilaev vsilaev released this 23 Oct 17:59
· 17 commits to master since this release

This milestone represents a mature, production-ready foundation for advanced asynchronous programming in Java. It bridges the gap between the non-blocking composition of CompletionStage and the true cancellation semantics of Future, while introducing powerful, modern concurrency primitives that go far beyond the standard JDK.
🌟 Major New Features

  1. Go-like Asynchronous Channels
    Inspired by Go’s concurrency model, we introduce a fully asynchronous, non-blocking implementation of channels in Java.
    Unlike existing libraries that rely on blocking and Project Loom magic, this implementation is purely promise-driven.
    Features full support for Select coordinators, enabling elegant, non-blocking multiplexing of multiple channel operations.
    Location: net.tascalate.concurrent.channels
  2. TaskScope: Structured Concurrency, Reimagined
    Tired of counting the endless JEPs for JDK Structured Concurrency (428, 437, 453, 462, 480...)? We provide a superior, stream-based alternative.
    Lazy Stream Consumption: scope.completions() yields tasks as a lazy Stream<Promise<?>>. Use standard Stream API operations (.filter(), .limit(), .takeWhile()) to implement complex aggregation logic (e.g., "first 3 successes, ignore failures") without custom joiners.
    Guaranteed Cancellation: Short-circuiting stream operations automatically trigger try-with-resources cleanup, instantly cancelling all remaining uncompleted tasks.
    Cross-Platform Context Propagation: The ContextRelay seamlessly bridges ThreadLocal, JDK 21+ ScopedValue, and framework-specific attributes (like Spring RequestAttributes) to all forked tasks.
  3. ThrottledExecutorService for Virtual Threads
    Executors.newVirtualThreadPerTaskExecutor() is powerful but dangerously uncontrollable.
    The new ThrottledExecutorService strictly bounds concurrent execution using a highly optimized, lock-free CAS-based counter (no Semaphore overhead).
    Features an intelligent permit hand-off mechanism: when a task finishes, it directly spawns the next queued task, avoiding unnecessary wake-up round-trips and minimizing latency.
    Note: Packaged in the Java 21+ Multi-Release JAR (MR-JAR) overlay.

⚡ Performance Optimizations
I care about those nanoseconds. This release includes dozens of core optimizations:

  • Multi-Release JAR (MR-JAR) VarHandle Overlays: Critical concurrency primitives (CallbackRegistry, SelectCoordinator, AggregatingPromise, ThrottledExecutorService) use VarHandle on Java 9+, eliminating the reflection overhead and wrapper allocations of Atomic*FieldUpdater for maximum CAS performance.
  • Zero Double-Wrapping: CompletableTask.submit() now intelligently detects if the target executor is a TaskExecutorService and delegates directly, bypassing the creation of redundant intermediate FutureTask wrappers.
  • Lock-Free Aggregation: Promises.all(), any(), and atLeast() use AtomicIntegerArray and primitive volatile counters with field updaters, avoiding per-instance AtomicInteger/AtomicBoolean allocations.

📚 Documentation: "If it's not documented, it doesn't exist"
Comprehensive User Manual: A newly authored, ~125-page user manual covering every aspect of the library, from basic promise composition to advanced structured concurrency patterns.
Exhaustive Javadocs: Nearly every class and method, including package-private utilities, is now fully documented with clear usage examples, parameter descriptions, and concurrency guarantees.

Backward compatibility
Code changes are required in several places:

  1. PromiseOrigin -> Promise.Origin
  2. Promises.partinioned* -> Promises.chunked*
  3. ContextVar / ContextRelay (previously ContextTrampoline) -- fully reworked API-s
  4. AsyncLock hierarchy refactored