一个EJB如何并行较长,CPU密集型的过程? [英] How can an EJB parallelize a long, CPU intensive process?

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

问题描述

该应用程序具有目前运行一台服务器(EJB方法)连续当客户端请求它在CPU密集型漫长的过程。

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信息

相关问题
<一href=\"http://stackoverflow.com/questions/533783/why-spawning-threads-in-j2ee-container-is-discouraged/533847#533847\">Why产卵线程气馁

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

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