0

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

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

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

谢谢你的帮助 !

4

2 回答 2

1

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.

于 2012-01-04T09:37:58.937 回答
0

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

于 2012-01-04T09:17:40.020 回答