Maybe this is a really dumb question, but please hear me out. I have a use case where I get many concurrent requests to do something for a particular input date. If there are two concurrent requests received for the same input date, the subsequent request should not proceed till the prior request has finished completely (for good reasons). What is the best way to use standard java.util.concurrent components to achieve this? My initial thoughts were around having a LockFactory which will vend locks and keep a copy to indicate that it is in use and on which the subsequent request will await(). However, this seems to have lot of boiler-plate code – any simpler trick that is eluding me?
Thanks in advance!
You can hash individual locks on the date’s time.
If you need the same day and not necessarily the exact date in milliseconds you can do something like
Then any request that needs mutual exclusion on a date
and so forth