I've started reading about the singleton session bean and the annotations used to employ container managed concurrency. I don't see the benfit of this compared to simply using the 'synchronized' keyword, so I suspect there is something important I am missing. Consider this example from the book "Enterprise JavaBeans 3.1" by Rubinger & Burke, O'Reilly:
@javax.ejb.Lock(javax.ejb.LockType.READ)
public String concurrentReadOnlyMethod(){...}
@javax.ejb.Lock(javax.ejb.LockType.WRITE)
public void allowOnlyOneWriteAtATimeMethod(String stringToSet){...}
How is this better than omitting the annotation all toghether in the read-case and using the synchronized
keyword in the write-case, like this:
public String concurrentReadOnlyMethod(){...}
public synchronized void allowOnlyOneWriteAtATimeMethod(String stringToSet){...}