Is it OK to lose the Java EE request scope when using Java 8 parallel Stream?

In our company, we are developing a quasi-standard REST service running in Wildfly 10.1. Each request has a tenant’s header, which will be intercepted by the filter, and the tenant’s information will be stored within the @RequestScopedbean for later use at the rest or at the service level. So far, so good. Now we find out that some code inside the service uses the Java 8 parallel thread and could not use the @RequestScopedbean to find the current tenant. We checked it several times. Using non-parallel threads solved this problem for us.

Is this normal behavior? We are really confused that using standard Java 8 features violates the expected behavior of the container.

Are there any other criminals we need to take care of?

+4
source share
1 answer

It seems that , than a parallel, it will spawn threads even in a controlled context.

However, RequestScoped is handled using ThreadLocal(we are still in the old old multithreaded model, i.e. HTTP request = 1).

So yes that's ok

+4
source

Source: https://habr.com/ru/post/1675598/


All Articles