Hi Folks
This concurrancy related question was for senior SDE role
Given the following class, multiple threads are calling the getMaxAmt and updateAmt methods
a. How would you modify the code to optimize for read throughput?
b. How woud you modify the code to optimize for write throughput?
class Question{
public static class MaxAmount{
private int maxAmt = Integer.MIN_VALUE;
public int getMaxAmt(){
return maxAmt;
}
public void updateAmt(int amt){
if(maxAmt<amt){
maxAmt=amt;
}
}
}
}The anwer I came up with was to use readwrite reentrant lock but it was not the optimal solution
How would you go about this?