Skip to content

softwaremill/jox

Repository files navigation

Jox

Ideas, suggestions, problems, questions CI Maven Central javadoc

Virtual-thread based safe concurrency & streaming for Java 21.

Includes:

  • Fast & scalable, completable channels, with Go-like selects
  • Programmer-friendly structured concurrency
  • Finite & infinite streaming using flows, with reactive streams compatibility, (blocking) I/O integration and a high-level, “functional” API

Find out more in the documentation available at jox.softwaremill.com.

A tour of Jox

Selectable channels:

var ch1 = Channel.<Integer>newBufferedDefaultChannel();
var ch2 = Channel.<Integer>newBufferedDefaultChannel();
var ch3 = Channel.<Integer>newBufferedDefaultChannel();

// send a value to two channels
ch2.send(29);
ch3.send(32);

var received = select(ch1.receiveClause(), ch2.receiveClause(), ch3.receiveClause());

A flow with time-based & parallel processing:

var nats =
  Flows.unfold(0, i -> Optional.of(Map.entry(i+1, i+1)));
 
Flows.range(1, 100, 1)
  .throttle(1, Duration.ofSeconds(1))
  .mapPar(4, i -> {
    Thread.sleep(5000);
    var j = i*3;
    return j+1;
  })
  .filter(i -> i % 2 == 0)
  .zip(nats)
  .runForeach(System.out::println);

Sructured concurrency scope:

var result = supervised(scope -> {
    var f1 = scope.fork(() -> {
        Thread.sleep(500);
        return 5;
    });
    var f2 = scope.fork(() -> {
        Thread.sleep(1000);
        return 6;
    });
    return f1.join() + f2.join();
});
System.out.println("result = " + result);

Feedback

Is what we are looking for!

Let us know in the issues, or our community forum.

Project sponsor

We offer commercial development services. Contact us to learn more!

Copyright

Copyright (C) 2023-2025 SoftwareMill https://softwaremill.com.

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy