简体   繁体   English

无状态会话bean中的同步方法无法在glassfish中正常工作

[英]synchronized method in stateless session bean not working as expected in glassfish

I have a war file deployed in glassfish. 我在Glassfish中部署了一个战争文件。 We have some stateless session beans and we have 1 synchronized method in it. 我们有一些无状态会话Bean,并且其中有1个同步方法。

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? glassfish是否有可能实例化此bean类的2个实例? 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. 规范甚至要求并发调用由不同的实例处理。:这是容器提供的服务之一:它确保并发调用是并发处理的,而不是顺序处理的,而且您可以自由地实现sesssion bean关心线程安全(例如,通过使用实例变量),因为容器会处理它。

What you want is a singleton . 您要的是单身人士

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM