For multiple lock attempts, use Java concurrent. ReentrantLock
•
Java
I noticed the following code block:
final Lock s = new reentrantlock(); for(int i = 0 ; i < 1000 ; i++) { s.lock(); System.out.println(i+" :" +s.tryLock()+" "); }
Printed matter:
0 :true 1 :true 2 :true 3 :true ...
It's strange - I want successive locks to fail because s will never be unlocked
What's wrong here?
Solution
Javadoc is your friend. You really should read it
From: reentrantlock lock()
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
二维码