Fixed deadlock when Transactor is restarted in the middle of a transaction
This commit is contained in:
parent
b98cfd5c1f
commit
4d130d544d
6 changed files with 82 additions and 63 deletions
|
|
@ -10,7 +10,7 @@ import java.util.concurrent.locks.{ReentrantReadWriteLock, ReentrantLock}
|
|||
* @author <a href="http://jonasboner.com">Jonas Bonér</a>
|
||||
*/
|
||||
class ReentrantGuard {
|
||||
private val lock = new ReentrantLock
|
||||
val lock = new ReentrantLock
|
||||
|
||||
def withGuard[T](body: => T): T = {
|
||||
lock.lock
|
||||
|
|
@ -20,6 +20,15 @@ class ReentrantGuard {
|
|||
lock.unlock
|
||||
}
|
||||
}
|
||||
|
||||
def tryWithGuard[T](body: => T): T = {
|
||||
while(!lock.tryLock) { Thread.sleep(10) } // wait on the monitor to be unlocked
|
||||
try {
|
||||
body
|
||||
} finally {
|
||||
lock.unlock
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue