EJB如何并行化长时间的CPU密集型进程? [英] How can an EJB parallelize a long, CPU intensive process?

查看:162
本文介绍了EJB如何并行化长时间的CPU密集型进程?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

应用程序具有CPU密集型长时间进程,目前在客户端请求时,它可以在一个服务器(EJB方法)上运行。

The application has a CPU intensive long process that currently runs on one server (an EJB method) serially when the client requests it.

理论上可以(从概念观点)将该进程拆分为N个块,并且并行执行它们,只要所有并行作业的输出可以在发送回发起进程的客户端之前收集并连接在一起即可。我想使用这种并行化来优化性能。

It’s theoretically possible (from a conceptual point of view) to split that process in N chunks and execute them in parallel, as long as the output of all parallel jobs can be collected and joined together before sending it back to the client that initiated the process. I’d like to use this parallelization to optimize performance.

如何实现与EJB的并行化?我知道我们不应该在EJB方法中创建线程。相反,我们应该发布消息驱动bean(MDB)消耗的消息(每个作业一个)。但是,它不再是同步电话了。在这种情况下,同步似乎是一个要求,因为我需要收集所有作业的输出才能将其发送回客户端。

How can I implement this parallelization with EJBs? I know that we should not create threads in a EJB method. Instead, we should publish messages (one per job) to be consumed by message driven beans (MDBs). But then it would not be a synchronous call anymore. And being synchronous seems to be a requirement in this case since I need to collect the output of all jobs before sending it back to the client.

是否有解决方案?

推荐答案

这个特定的问题已经出现在多个场合,我将总结一下,有几个可能的解决方案,其中只有1个我会推荐。

This particular question has come up on multiple occasions and I will summarize that there are several possible solutions, only 1 of which I would recommend.

使用commonj API中的WorkManager。它允许Java EE容器中的托管线程,并专门设计为适合您的用例。如果您正在使用WebSphere或WebLogic,则这些API已在您的服务器中可用。对于其他人,您将必须将自己的第三方解决方案付诸实施。

Use a WorkManager from the commonj API. It allows for managed threads in a Java EE container and is specifically designed to fit your use case. If you are using WebSphere or WebLogic, these API's are already available in your server. For others your will have to put a third party solution in yourself.

WorkManager信息

相关问题
为什么不鼓励生成线程

这篇关于EJB如何并行化长时间的CPU密集型进程?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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