Seema, thanks for pointing out the "fairness" thing. I was totally unaware of this. And yes, my write thread could just starve because of this. Thanks for letting me know. I knew about the edge case and I was thinking of adding all the read threads in a queue and make them wait before acquiring the write lock. I was planning to do this manually. But then with another teammate, it was decided to first let the starvation happen and then we'll see if we should solve the problem. Thanks for bringing this up.

See the beauty of writing public posts. :D The world collaborates.

Correct me if I am wrong on this. I could just pass a boolean in the constructor of ReentrantReadWriteLock to set the fairness policy as per the official doc? `new ReentrantReadWriteLock(true)`? And this would just solve the starvation problem?

--

--

I write code. Engineer at CoinDCX.

Love podcasts or audiobooks? Learn on the go with our new app.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store