Synchronizing method access based on instance-specific criteria in Java
I have a Java application where multiple threads are executing methods on different instances of a class (RepositoryA). Each instance of RepositoryA performs database operations (upsert method) based on a unique identifier. I need to ensure that only one thread can execute the upsert method at any given time across all instances of RepositoryA.