Java EE应用程序中的线程死锁

问题描述:

我是Java EE的新手。我想知道Java EE应用程序层中是否存在一些常见的死锁情况,这是因为使用Java同步原语 - synchronized关键字。如果是,可以帮助举个例子吗?

I am a newbie to Java EE. I wonder if there are some common deadlock cases in Java EE application layer, resulting from using Java synchronization primitive - synchronized keyword. If yes, could help give an example?

从EJB 3.1规范,第21.2.2节。编程限制:

From the EJB 3.1 spec, Chapter 21.2.2. Programming Restrictions:


企业bean不能使用线程
同步原语到
同步执行多个
实例,除非它是具有bean管理的
并发的Singleton
会话bean。

An enterprise bean must not use thread synchronization primitives to synchronize execution of multiple instances, except if it is a Singleton session bean with bean-managed concurrency.

推理也很有意思:


如果
EJB容器跨多个JVM分布企业
bean的实例,则同步将不起作用。

Synchronization would not work if the EJB container distributed enterprise bean’s instances across multiple JVMs.