Usecase : Rotation of credentials for a datastore
What I want :
- When updateCredentials is called, it will wait until it all threads are done fetching credentials (via the synchronize) to update the credentials to the new ones.
- I DO NOT want calls to doSomeQuery making each other wait to fetch credentials. This object can be used in multiple threads and its a wasteful wait.
Is there a method / pattern to achieve this? The code sample below achieves item 1 but not item 2.
private Object credentialUpdate = new Object();
public void updateCredentials(String user, String pass) {
synchronize(credentialUpdate) {
this.user = user;
this.pass = pass;
}
}
public void doSomeQuery(String query) {
String curUser;
String curPass;
synchronize(credentialUpdate) {
curUser = this.user;
curPass;
}
// execute query
}