This week's book giveaway is in the Java in General forum. We're giving away four copies of Beginning Java 17 Fundamentals: Object-Oriented Programming in Java 17 and have ishori Sharan & Adam L Davis on-line! See this thread for details.
Acquires the read lock only if the write lock is not held by another thread at the time of invocation.
i start thread`s that will get read lock, pause it for main thread can get write lock.
than after getting write lock i make pause main threads for threads have chance get it read lock - and they did it.
when i test same with lock() - it work as i expected, but this time i see that tryLock get lock even if i had already acquired write lock.
What is problem???
Sergej you can read the API Docs for such confusions. The API docs for tryLock method states:
tryLock Java Docs wrote:Acquires the lock only if it is free at the time of invocation.
Acquires the lock if it is available and returns immediately with the value true. If the lock is not available then this method will return immediately with the value false.