Sharing a Java synchronized block across a cluster, or using a global lock?

前端 未结 5 1278
死守一世寂寞
死守一世寂寞 2021-02-01 07:14

I have some code that I want to only allow access to by one thread. I know how to accomplish this using either synchronized blocks or methods, but will this work i

5条回答
  •  迷失自我
    2021-02-01 07:43

    Couldn't you simply lock the table (or entire db) for updates, so when the first node in obtained the lock all other nodes would not be able to write. Subsequent nodes would wait, and when the lock is released the code would be updated so no record update would be required.

提交回复
热议问题