...
Wiki Markup |
---|
{snippet:url=openejb3/examples/simple-singleton/src/main/java/org/superbiz/registry/PropertyRegistryBean.java|lang=java|id=code} |
Here we see a bean that uses the Container-Managed Concurrency option, the default. With @ConcurrencyManagement(CONTAINER) the container controls whether multi-threaded access should be allowed to the bean (@Lock(READ)) or if single-threaded access should be enforced (@Lock(WRITE)).
Wiki Markup |
---|
{snippet:url=openejb3/examples/simple-singleton/src/main/java/org/superbiz/registry/ComponentRegistryBean.java|lang=java|id=code} |
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.
...
Wiki Markup |
---|
{snippet:url=openejb3/examples/simple-singleton/src/test/java/org/superbiz/registry/ComponentRegistryBeanTest.java|lang=java|id=code} |
Running
Running the example is fairly simple. In the "simple-singleton" directory run:
...