java - How to test if a writelock is locked with trylock -


what need do: method acquires read or write lock, method sets free. i've been reading , found reentrantreadwritelock, has 2 nested classes, reentrantreadwritelock.readlock , reentrantreadwritelock.writelock, far understand, can obtained this:

 private final reentrantreadwritelock readwritelock = new  reentrantreadwritelock(); private final lock read = readwritelock.readlock(); private final lock write = readwritelock.writelock(); 

as example. understanding readlock() , writelock() 2 constructor give lock object. , test if lock being used or not trylock

it's don't understand how know if there's lock in place, , instead writelock.trylock() seems acquire it, if possible. , can like:

if (read.trylock()) {     read.unlock(); } else {     return false; } 

and try aquire lock , "and returns value true". still holds read lock, said, fine, unlock it.

but that's not want, because want free lock (if was) set method. don't want method lock anything, want test lock, if it's in place, unlock.

different ways of doing (but not know if valid): holdslock , isheldbycurrentthread, used object , reentrantlocks, , don't know guess way of solving problem create 2 reentrantlocks, use 1 write lock , read lock, , use isheldbycurrentthread merely check described above (but again, believe this, don't know).

sorry if it's confusing, please ask me clarify needed, tried best explaining issue.


Comments

Popular posts from this blog

node.js - Using Node without global install -

How to access a php class file from PHPFox framework into javascript code written in simple HTML file? -

java - Null response to php query in android, even though php works properly -