EJB 3.1 container managed concurrency vs. synchronized

前端 未结 2 1541
野趣味
野趣味 2020-12-31 16:07

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 u

2条回答
  •  清酒与你
    2020-12-31 16:42

    Simple.

    The "concurrentReadOnlyMethod" is not synchronized at all, so it doesn't gain other side effect of synchronization (such as effects on variables within the memory model). Also, the READ lock will block the WRITE lock, so with just synchronized, you can have two threads running both methods simultaneously, whereas with the READ/WRITE lock you won't.

    Obviously there's more value when you have several READ locks and few WRITE locks, as all of the READ locks can be shared and run simultaneously, while the WRITE locks act more like a normal synchronized.

提交回复
热议问题