Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

The default @Lock value for a method is @Lock(WRITE). The code above uses the @Lock(READ) annotation on bean class to change the default so that multi-threaded access is granted by default. We then only need to apply the @Lock(WRITE) annotation to the methods that modify the state of the bean. The important thing to keep in mind is that when an @Lock(WRITE) method is invoked the container will block all access to the bean, even to @Lock(READ) methods, until the method completes. This is very good and is an advanced form of synchronization that allows for safe multi-threaded reading and single-threaded writing.

Test

...

Case

Wiki Markup
{snippet:url=openejb3/examples/simple-singleton/src/test/java/org/superbiz/registry/ComponentRegistryBeanTest.java|lang=java|id=code}

...