无状态会话bean中的synchronized方法在glassfish中没有像预期的那样工作 [英] synchronized method in stateless session bean not working as expected in glassfish
问题描述
但是,我注意到多于1个线程能够同时输入synchronized方法。 Glassfish是否有可能实例化这个bean类的两个实例?有没有办法解决这个问题?
是的,当然这是可能的。该规范甚至规定 并发调用由不同实例处理:这是容器提供的服务之一:它确保并发调用并发处理,而不是顺序处理,而你自由地实现你的sesssion bean而不关心线程安全性(例如,通过使用实例变量),因为容器负责它。
你想要的是<
单身人士
I have a war file deployed in glassfish. We have some stateless session beans and we have 1 synchronized method in it.
However, I am noticing that more than 1 thread is able to enter the synchronized method concurrently. Is it possible that glassfish is instantiating 2 instances of this bean class? Is there any way around this?
Yes, of course it's possible. The spec even mandates that concurrent calls are handled by different instances.: this is one of the services offered by the container: it makes sure that concurrent calls are handled concurrently, and not sequentially, and you're free to implement your sesssion bean without caring about thread-safety (for example, by using instance variables), because the container takes care of it.
What you want is a singleton.
这篇关于无状态会话bean中的synchronized方法在glassfish中没有像预期的那样工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!