Scale up as you grow — whether you're running one virtual machine or ten thousand.

From GPU-powered inference and Kubernetes to managed databases and storage, get everything you need to build, scale, and deploy intelligent applications.

I really appreciate your effort on putting the consolidated information in one place in nice manner… thank you very much.
- Nagaraju
Hello Friend, Just let me know if I am wrong- I thing lock.tryLock(10, TimeUnit.SECONDS); in run method i trying to access lock on ConcurrencyLockExample object instead of Resource object. If you want to get lock on Resource object than Lock lock= new Reentrant(); should be added in Resource Class;
- Dharmendra
Hi, I like to thank you for providing such a good explaination with simple example.
- amit nandode
Hi, I guess you did a mistake here: As you can see that, I am using tryLock() method to make sure my thread waits only for definite time and if it’s not getting the lock on object, it’s just logging and exiting. Since tryLock returns false if the lock hasn’t been acquired and doesn’t raise an exception, you should place resource.doSomething() in IF block.
- 3biga
Hi Pankaj, Can you please also explain the different Condition of lock & Lock Fairness with an example.
- HIMANSU NAYAK
Hi Pankaj, I created a test class to run this code. public class CocurrencyLockMain { public static void main(String… args) { Resource resource = new Resource(); new Thread(new ConcurrencyLock(resource)).start(); new Thread(new ConcurrencyLock(resource)).start(); } } i was expecting the second thread should wait till the first thread execution completed but both the thread were running simultaneously. Can you please explain what is wrong in my understanding.
- HIMANSU NAYAK
Hey just wanted to know why do we use ReadLock…? when multiple threads are allowed so what is need of ReadLock…? access it without any lock.
- Hrishi
Thanks Pankaj for this blog. I could get a brief information about the Lock API. It’s simple and good. It may become more useful if there is an example for each of those cases: Condition, ReadWriteLock and ReentrantLock.
- Bhaskar