EJB @Asynchronous to retrieve real time inserted row in JSF seems to be thread locked

后端 未结 1 1582
一生所求
一生所求 2021-01-18 06:24

I am trying to achieve the following :

EJB3 Singleton

@Singleton
@Startup
public class SomeSingleton implements SomeSingletonLoca         


        
相关标签:
1条回答
  • 2021-01-18 06:40

    A @Singleton is indeed by default read/write locked. This is not strictly related to transactions, but to concurrency. See also a.o. Java EE 7 tutorial on the subject.

    One way to solve it is to set the @ConcurrencyManagement to BEAN. This way you basically tell the container to not worry about concurrency at all and that you take all responsibility on your own.

    @Singleton
    @ConcurrencyManagement(ConcurrencyManagementType.BEAN)
    public class SomeSingleton {}
    

    Another way is to explicitly set @Lock to READ on the class or the read-only methods so that they can concurrently be invoked. Only when a method with an explicit @Lock(LockType.WRITE) is invoked on the same instance, then the lock will occur.

    @Singleton
    @Lock(LockType.READ)
    public class SomeSingleton {}
    
    0 讨论(0)
提交回复
热议问题