Ken Geis 14 Years Ago I don't see why this complexity is needed. With a BlockingCache, the acquisition and release of the lock is done within the get(..) methods. In your example, thread A cannot even attempt to acquire a lock on BlockingCache2 until it gets a result from BlockingCache1 (thus releasing the lock on BlockingCache1.) Am I wrong? Please sign in to reply. Reply as... Cancel Shuyang Zhou Ken Geis 14 Years Ago In pic 2, Thread A has locked BlockingCache 1, which means it got a null from the get(), so it has to go ahead to populate the cache element, before it finishes this, all other threads hitting BlockingCache 1 with same key will lock there. But to populate the BlockingCache 1, thread A needs a BlockingCache 2 which just happened to be locked by Thread B, on the other side thread B can't move further because it was waiting thread A to release BlockingCache1, so deadlock happened. I think you don't understand how does ehcache's BlockingCache work, BlockingCache will return a null for the first arrived thread, and that thread is responsible for populating the missed cache element, all other threads will block there until the element has been populated. Please sign in to reply. Reply as... Cancel Ken Geis Shuyang Zhou 14 Years Ago I see. It wasn't clear to me that an item from cache 2 was needed to populate cache 1. Please sign in to reply. Reply as... Cancel
Shuyang Zhou Ken Geis 14 Years Ago In pic 2, Thread A has locked BlockingCache 1, which means it got a null from the get(), so it has to go ahead to populate the cache element, before it finishes this, all other threads hitting BlockingCache 1 with same key will lock there. But to populate the BlockingCache 1, thread A needs a BlockingCache 2 which just happened to be locked by Thread B, on the other side thread B can't move further because it was waiting thread A to release BlockingCache1, so deadlock happened. I think you don't understand how does ehcache's BlockingCache work, BlockingCache will return a null for the first arrived thread, and that thread is responsible for populating the missed cache element, all other threads will block there until the element has been populated. Please sign in to reply. Reply as... Cancel Ken Geis Shuyang Zhou 14 Years Ago I see. It wasn't clear to me that an item from cache 2 was needed to populate cache 1. Please sign in to reply. Reply as... Cancel
Ken Geis Shuyang Zhou 14 Years Ago I see. It wasn't clear to me that an item from cache 2 was needed to populate cache 1. Please sign in to reply. Reply as... Cancel