I have a requirement in java to write a method which will be accessed by multiple threads simultaneously. But it should allow only one thread per customer at a time. Means any different customer threads can work same time. Customers are separated by customer id, which is available as an argument to the function.
What is the best way to achieve this? Its somewhat similar to implementing a semaphore but the counter should be on a field/variable value.