java - ReentrantReadWriteLock and synchronized blocks -


If I have ReentrantReadWriteLock , and I can use it as a lock in the synchronized block Do other threads still release your locks?

For example:

  ReentrantReadWriteLock lock = new ReentrantReadWriteLock (true); Public Zero doSomething () {synchronize (lock) {lock.readLock (). Lock (); // do stuff lock.readLock () Unlock (); }}   

If I call doSomething () and another thread keeps the already read lock, does it continue to read the thread read? Can do?

When I call doSomething () , then I will synchronize on ReentrantReadWriteLock and then try to get the lock to be read. Since there is a pre-read lock, I will block that lock until it is released. I'm curious to know whether reading lock can be released since being synchronized on the lock.

Syncing on a REINrent Redirect Lock object seems like an incredibly bad idea. Locking completely free lock. First of all, it locks the mute x built in each object (in this case, the restartreddrytalk object), and then it locks the lock.

Whenever you see the lock, you should ask this question, "Is irrevocable that the lock should be protected?" There is another way to ask, "If your lock was not there, can your data be corrupted?"

OK, synchronize (lock) What does it do?

And, what lock.readLock (). Lock () to protect?

If both answers are the same, why use two lock?

If it was above me, then I would not even read / write lock in the first place

You can change your example:

  object lock = new object (); Public Zero doSomething () {synchronize (lock) {// do stuff}   

As far as you have shown us the code, it will not behave in any different way (though, It can change how your example interacts with other codes that you have not shown to us.)

Comments

Popular posts from this blog

Java - Error: no suitable method found for add(int, java.lang.String) -

java - JPA TypedQuery: Parameter value element did not match expected type -

c++ - static template member variable has internal linkage but is not defined -