https://github.com/t1/jee-parallel-stream-http-demo
Experiments with parallel streams of Jakarta EE managed threads doing http requests
https://github.com/t1/jee-parallel-stream-http-demo
Last synced: 3 months ago
JSON representation
Experiments with parallel streams of Jakarta EE managed threads doing http requests
- Host: GitHub
- URL: https://github.com/t1/jee-parallel-stream-http-demo
- Owner: t1
- Created: 2023-05-12T16:10:17.000Z (about 3 years ago)
- Default Branch: trunk
- Last Pushed: 2026-03-11T09:13:03.000Z (4 months ago)
- Last Synced: 2026-03-11T16:06:22.080Z (4 months ago)
- Language: Java
- Homepage:
- Size: 32.2 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.adoc
Awesome Lists containing this project
README
= Jakarta EE Parallel Stream Http Demo
Experiments with parallel streams of Jakarta EE managed threads doing http requests.
It has two REST resources:
|===
|URL |Result
|http://localhost:8080/\{n}plus\{m}
|the sum of `n` and `m`
|http://localhost:8080/sum\{n}
|the sum of a stream of 1 to `n`, adding 1 to every element, e.g. `sum2` = 5
|===
The `sum` resource does `n` parallel http requests to the `plus` resource.
As I understand the https://jakarta.ee/specifications/concurrency/3.0/jakarta-concurrency-spec-3.0.html#managedthreadfactory[Jakarta Concurrency Spec 3.0] (esp. the Javadoc of the https://jakarta.ee/specifications/concurrency/3.0/apidocs/jakarta/enterprise/concurrent/managedthreadfactory[ManagedThreadFactory] class), this should be possible (as I've implemented in `Parallel.java`):
* Inject a `ManagedThreadFactory` via `@Resource`.
* Create a `ForkJoinPool` based on that.
* Submit tasks to that pool.
* Tasks are managed and can access, e.g., `@RequestScoped` beans.
I can see that the worker threads are not from the common pool, so I'd assume that they are actually managed.
But it fails on WildFly with `WELD-001303: No active contexts for scope type jakarta.enterprise.context.RequestScoped`.
If I do it in a traditional way (i.e. with a non-parallel stream and an intermediate `.toList().stream()`), it works.
*Please correct me if I'm wrong!*
To reproduce it, just run `mvn wildfly:dev` and call `http://localhost/sum2`.