java - ReentrantReadWriteLock and synchronized blocks -
If I have For example: If I call When I call 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, And, what 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: 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.) ReentrantReadWriteLock , and I can use it as a lock in the synchronized block Do other threads still release your locks?
ReentrantReadWriteLock lock = new ReentrantReadWriteLock (true); Public Zero doSomething () {synchronize (lock) {lock.readLock (). Lock (); // do stuff lock.readLock () Unlock (); }}
doSomething () and another thread keeps the already read lock, does it continue to read the thread read? Can do?
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.
synchronize (lock) What does it do?
lock.readLock (). Lock () to protect?
object lock = new object (); Public Zero doSomething () {synchronize (lock) {// do stuff}
Comments
Post a Comment