EJB - 架构问题

发布于 2024-12-24 18:25:52 字数 385 浏览 3 评论 0原文

我目前正在编写一个新的 EJB 应用程序,它基本上应该从 Web 服务接收消息并根据该消息内容启动下载过程。该应用程序将在 Glassfish 3.1.1 上运行。

我的第一个想法是创建一个单例 bean,它可以从 Web 服务读取消息并使用有状态会话 bean 来启动和处理下载本身。我需要使用有状态 bean,因为我需要在单例和有状态 bean 之间有一个转换状态(下载状态等)。

“问题”是,如果我从 Web 服务收到多条消息,我应该在其中开始多次下载并行,当然每个下载都有自己的上下文。我应该如何实现这一点,就好像我从我的单例调用有状态会话 bean 一样,我总是会得到相同的 bean,对吗?我看到的唯一解决方案是使用从我的单例创建和启动的线程,但这不是 EJB 规范允许的...

感谢您的帮助!

I'm currently writing a new EJB application which basically is supposed to receive messages from a web service and launch a downloading process based on this message content. This application will run on Glassfish 3.1.1.

My first idea was to create a singleton bean that would read the messages from the web service and use a stateful session bean to initiate and handle the download itself. I need to use stateful beans because I need to have a convertational state between my singleton and stateful bean (download status, etc.)

The "problem" is if I receive several messages from the web service I'm supposed to start several downloads in parallel, each download with its own context of course. How am I supposed to achieve this as if I invoke a stateful session bean from my singleton I'll always get the same bean, correct? The only solution I see is to use threads that would be created and launched from my singleton but this is not permitted by EJB specification...

Thanks for your help !

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

<逆流佳人身旁 2024-12-31 18:25:52

我认为您不想要这里有状态会话 bean。有状态 Bean 的要点是在会话范围内维护状态,即与特定客户端的关系。在您的情况下,每个客户端都没有一次下载(甚至有客户端吗?),这意味着这不是合适的范围。

如果您只需要多个线程,请使用带有 @Asynchronous 的无状态 bean 方法。您可能必须使用单例回调来处理状态更新。

I don't think you want a stateful session bean here. The point of a stateful bean is that that maintains state in the scope of a session, which is a relationship with a particular client. In your case, there isn't one download per client (are there even any clients?), which means that this is not an appropriate scope.

If you just want multiple threads, use a stateless bean with an @Asynchronous method. You would probably have to handle status updates using a callback to the singleton.

笑梦风尘 2024-12-31 18:25:52

为什么这里需要一个单例 bean?仅仅有状态会话 bean 还不够好吗?你想要同时下载,你想要有状态,那么为什么要使用单例呢?你能再解释一下吗?

Why do you need a singleton bean here? Is just stateful session bean is not good enough? You want simultaneous downloads, you want statefulness, so why to use singleton? Can you explain a little bit more?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文