We are creating a rest application. And we have an edge condition where parallel actions are not supported on same object.
For example : 

```
Not supported in parallel
    Request 1 for action XYZ for object  A
    Request 2 for action XYZ for object  A
    Request 3 for action ABC for object  A

Supported in parallel
    Request 1 for action XYZ for object  A
    Request 2 for action XYZ for object  B
    Request 3 for action ABC for object  C

```

Now, the **object** count is not fixed. we can have n number of such objects.

I want that if a request for object A is under progress then other request for object A should wait for existing task on object A to get over. 

But I am not able to figure out the algorithm for this purpose. 

I could plan for below design but not able to figure out on how to use the locking since all objects can be different. 

* A queue which stores the entry for object A when request comes.
* Entry gets deleted if response is sent
* If an entry is already present, then wait for existing request to get over.
* If entry not present, then execute immediately.

Now task on object A should not impact the task on object B. So they must accept unique locks.

And also, request cannot go standalone and be queued. Somehow I have to make the current thread sleep so that I can send response to user.

Can anyone guide here?