java - EJB 中的多线程

标签 java multithreading ejb-3.0

我正在学习 EJB,到目前为止我已经读到 EJB 中不允许使用多线程,因为容器应该关心线程安全并让开发人员只关注业务逻辑,所以基本上意味着 EJB 确保只有一个线程可以同时访问 Session bean 中的方法。

当我们有许多用户访问 EJB 中的同一个方法时会发生什么? 容器是序列化访问,还是创建不同的 bean 实例,每个线程一个?

谁能解释一下这方面的政策是什么?另外我有点困惑,为什么如果不允许多线程,那么我们不能创建自己的线程,为什么我们有这个 @Asynchronous 注释?

最佳答案

是的,它创建了多个实例,并将它们集中在一起。查看official Oracle documentation :

Because a stateless session bean is never passivated, its lifecycle has only two stages: nonexistent and ready for the invocation of business methods. Figure 22-4 illustrates the stages of a stateless session bean.

The EJB container typically creates and maintains a pool of stateless session beans, beginning the stateless session bean’s lifecycle. The container performs any dependency injection and then invokes the method annotated @PostConstruct, if it exists. The bean is now ready to have its business methods invoked by a client.

At the end of the lifecycle, the EJB container calls the method annotated @PreDestroy, if it exists. The bean’s instance is then ready for garbage collection.

关于java - EJB 中的多线程,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30013472/

相关文章:

java - 在同一 session 中最有效地实现重复浏览器自动化

java - 如何使用数组将 csv 转换为 json

java - 如何重命名Java的线程

c# - 静态代码如何与多线程一起运行?

java - EJB 远程方法中不匹配的序列化 UID - java.util.date 和 DBTimestamp

java - 用 '@Async' 注释的方法必须是可覆盖的

java - 使用 while 循环弹跳球,我需要将每次弹跳减少 30% 直到 0,然后退出循环以避免无限循环

android - 处理程序调用 notifyDataSetChanged() 未执行

java - ejb 无状态类是否必须公开?

java - EJB 异常 : Failed to acquire the pool semaphore