1

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?

user674669
  • 10,681
  • 15
  • 72
  • 105

1 Answers1

5

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.

JB Nizet
  • 678,734
  • 91
  • 1,224
  • 1,255