java method synchronization and read/write mutual exclusion

后端 未结 5 1466
醉酒成梦
醉酒成梦 2021-02-01 05:28

I have two methods read() and write() as below in a class.

class Store
{

  public void write()
  {
    // write to store;
  }

  publi         


        
5条回答
  •  梦如初夏
    2021-02-01 05:32

    synchronized is the simplest solution so you should explain what you mean by "doesn't seem like work for me" and perhaps show us how you used it.

    The better solution is to use ReentrantReadWriteLock because it allows concurrent access to readers as well.

提交回复
热议问题