Discussion:
[jboss-user] [EJB3] - How do javax.ejb.Singletons work?
John Lee
2013-03-25 19:47:50 UTC
Permalink
John Lee [https://community.jboss.org/people/jhn134910] created the discussion

"How do javax.ejb.Singletons work?"

To view the discussion, visit: https://community.jboss.org/message/804718#804718

--------------------------------------------------------------
Are singletons implemented using synchronized methods?

I have an EJB singleton, say:

@Singleton
public void MySingleton {
     ...

     public void receive(final String string) {
          x.callMyBlockingMethod(string);
     }
}

Consider the scenario, where this is running in JBOSS standalone. This singleton shall be called from multiple threads, with names Thread-1, Thread-2 and Thread-3 in that order. Thread-1 calls the blocking method which doesn't return for 10 seconds. Thread-2 arrives at the receive method shortly after Thread-1, followed shortly by Thread-3 and both wait for the lock to be released by Thread-1. Is there anything in the EJB standard regarding singletons that guarantees that Thread-2 shall aquire the lock before Thread-3 once Thread-1 releases it?
Loading...