Java threads locking on a specific object

前端 未结 10 1000
抹茶落季
抹茶落季 2020-12-12 00:06

I have a web application and I am using Oracle database and I have a method basically like this:

public static void saveSomethingImportantToDataBase(Object t         


        
10条回答
  •  旧巷少年郎
    2020-12-12 00:27

    I don't think you have any choice but to take one of the solutions that you do not seem to want to do.

    In your case, I don't think any type of synchronization on the objectYouWantToSave is going to work since they are based on web requests. Therefore each request (on its own thread) is most likely going to have it's own instance of the object. Even though they might be considered logically equal, that doesn't matter for synchronization.

提交回复
热议问题