Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Migrated to Confluence 4.0

...

Literally 100% of the Singleton locking we're talking about is taken from this interface and its javadoc is a great source of information. It's safe to imagine that under the covers the Singleton Container has an instance of ReadWriteLock which it uses to enforce the locking for all the Singleton bean's methods. Essentially:

  • @Lock(READ) == theSingletonReadWriteLock.readLock().lock()
  • @Lock(WRITE) == theSingletonReadWriteLock.writeLock().lock()

The EJB container may use something other than ReadWriteLock but the semantics of a ReadWriteLock must be followed. Internally, we use an instance of java.util.concurrent.ReentrantReadWriteLock which supports correct memory synchronization, some reentrancy, lock downgrading, and more.

...

Singletons can be declared in the ejb-jar.xml as follows:

Code Block
xmlxml
titleMETA-INF/ejb-jar.xml
xml
<ejb-jar>
  <enterprise-beans>
    <session>
      <ejb-name>MySingletonBean</ejb-name>
      <ejb-class>org.superbiz.MySingletonBean</ejb-class>
      <session-type>Singleton</session-type>
      <load-on-startup/>
      <depends-on>
        <ejb-name>SingletonFoo</ejb-name>
        <ejb-name>SingletonBar</ejb-name>
      </depends-on>
    </session>
  </enterprise-beans>
</ejb-jar>