且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

在Java EE容器中使用Java 8并行流是否不鼓励?

更新时间:2023-12-03 13:46:52

lambda-dev邮件列表讨论:产生线程的方式不是不鼓励 - 但不会在Java EE环境中为您做任何事情。



从链接的讨论中:


Java EE并发人员已经通过
进行了这个讨论,目前的结果是,在$ b内运行时,FJP会优雅地降级为
单线程(甚至调用者上下文)执行$ b EE容器

所以,您可以在程序或库中安全地使用并行流在两个上下文中运行。当它在SE环境中运行时,它将与魔法平行的shenanigans一起使用 - 但是当它在EE环境中运行时,它会优雅地降级为串行执行。



注意:以上引用的短语是未来时态 - 有没有人引用一些确定的文档?


Given that spawning threads in Java EE containers are discouraged. Would using the Java 8 parallel streams, which may spawn threads, inside Java EE be discouraged too?

The way I read it from the lambda-dev mailing list discussion mentioned in the comments: it's not discouraged the way spawning threads is - but won't do anything much for you in a Java EE context.

From the linked discussion:

the Java EE concurrency folks had been already talked through this, and the current outcome is that FJP will gracefully degrade to single-threaded (even caller-context) execution when running from within the EE container

So you're able to safely use parallel streams in a procedure or library that runs in both contexts. When it's run in a SE environment, it will make with the magical parallel shenanigans - but when it's run in an EE environment it will gracefully degrade to serial execution.

Note: the phrase quoted above is future tense - does anyone have a citation for some definitive documentation?