https://github.com/softwaremill/jox
Fast and Scalable Channels in Java
https://github.com/softwaremill/jox
channels concurrency java loom
Last synced: about 2 months ago
JSON representation
Fast and Scalable Channels in Java
- Host: GitHub
- URL: https://github.com/softwaremill/jox
- Owner: softwaremill
- License: apache-2.0
- Created: 2023-11-08T12:58:16.000Z (almost 2 years ago)
- Default Branch: main
- Last Pushed: 2024-05-22T11:06:30.000Z (over 1 year ago)
- Last Synced: 2024-05-22T11:56:02.300Z (over 1 year ago)
- Topics: channels, concurrency, java, loom
- Language: Java
- Homepage:
- Size: 349 KB
- Stars: 160
- Watchers: 7
- Forks: 5
- Open Issues: 7
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Jox
[](https://softwaremill.community/c/open-source/11)
[](https://github.com/softwaremill/jox/actions?query=workflow%3A%22CI%22)
[](https://maven-badges.herokuapp.com/maven-central/com.softwaremill.jox/channels)
[](https://javadoc.io/doc/com.softwaremill.jox/channels)[Virtual-thread](https://docs.oracle.com/en/java/javase/21/core/virtual-threads.html) based safe concurrency & streaming
for Java 21+.Includes:
* Fast & scalable, completable channels, with Go-like `select`s
* Programmer-friendly structured concurrency
* Finite & infinite streaming using flows, with reactive streams compatibility, (blocking) I/O integration and a
high-level, “functional” APIFind out more in the documentation available at [jox.softwaremill.com](https://jox.softwaremill.com/).
## A tour of Jox
Selectable [channels](https://jox.softwaremill.com/latest/channels.html):
```
var ch1 = Channel.newBufferedDefaultChannel();
var ch2 = Channel.newBufferedDefaultChannel();
var ch3 = Channel.newBufferedDefaultChannel();// send a value to two channels
ch2.send(29);
ch3.send(32);var received = select(ch1.receiveClause(), ch2.receiveClause(), ch3.receiveClause());
```A push-based, backpressured [flow](https://jox.softwaremill.com/latest/flows.html) 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](https://jox.softwaremill.com/latest/structured.html) 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](https://softwaremill.community/c/open-source/11).
## Project sponsor
We offer commercial development services. [Contact us](https://softwaremill.com) to learn more!
## Building & working on Jox
Jox uses the spotless maven plugin to format code. The formatting is automatically applied during compilation.
Formatting can be checked using `mvn spotless:check` and applied with `mvn spotless:apply`.When using VS Code, format-on-save should be disabled (see the pom.xml).
For IntelliJ, it might be necessary to install the spotless plugin to properly reformat the sources.## Copyright
Copyright (C) 2023-2025 SoftwareMill [https://softwaremill.com](https://softwaremill.com).