An open API service indexing awesome lists of open source software.

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

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`.