在Java EE容器中使用Java 8并行流是否不鼓励? [英] Is it discouraged using Java 8 parallel streams inside a Java EE container?

查看:118
本文介绍了在Java EE容器中使用Java 8并行流是否不鼓励?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

鉴于不鼓励在Java EE容器中生成线程。将使用可能产生线程的 Java 8并行流在Java EE内部也不鼓励?

解决方案

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?

这篇关于在Java EE容器中使用Java 8并行流是否不鼓励?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆