Никак не могу понять, что имел в виду Joshua Bloch в своей книге "Effective Java":
Chapter 9
Item 49: Avoid excessive synchronization
"Invoking an alien method from within a synchronized region can cause failures more severe
than deadlocks if the alien method is invoked while the invariants protected by the
synchronized region are temporarily invalid. (This cannot happen in the broken work queue
example because the queue is in a consistent state when processItem is invoked.) Such
failures do not involve the creation of a new thread from within the alien method; they occur
when the alien method itself calls back in to the faulty class. Because locks in the Java
programming language are recursive, such calls won't deadlock as they would if they were
made by another thread. The calling thread already holds the lock, so the thread will succeed
when it tries to acquire the lock a second time, even though there is another conceptually
unrelated operation in progress on the data protected by the lock. The consequences of such a
failure can be catastrophic; in essence, the lock has failed to do its job. Recursive locks
simplify the construction of multithreaded object-oriented programs, but they can turn
liveness failures into safety failures."
У кого — нибудь есть какие-нибудь соображения, друзья ?
Заранее спасибо!
Здравствуйте, Jackson86, Вы писали:
J>Никак не могу понять, что имел в виду Joshua Bloch в своей книге "Effective Java": J>Item 49: Avoid excessive synchronization
Не увлекайтесь синхронизацией, ибо не спасает она от всех проблем. Например один и тот же код, защищеный локом, можно вызвать до освобождения лока. Например коллбэком в том же потоке.
Re[2]: Не могу понять, о чем пишет Joshua Bloch...