synchronized method in stateless session bean not working as expected in glassfish

左心房为你撑大大i 提交于 2019-12-11 10:45:20

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/25295758/synchronized-method-in-stateless-session-bean-not-working-as-expected-in-glassfi

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!