无状态会话bean中的synchronized方法在glassfish中没有像预期的那样工作 [英] synchronized method in stateless session bean not working as expected in glassfish

查看:79
本文介绍了无状态会话bean中的synchronized方法在glassfish中没有像预期的那样工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个在glassfish中部署的战争文件。我们有一些无状态会话bean,我们有1个同步方法。



但是,我注意到多于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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆