It is essentially hard to remove deadlocks from multithreaded code. Thus, it would be a necessary breakthrough to provide practical techniques for incorporating code that is not deadlock free and that may be unchangeable, invisible or dynamically loaded from networks into dependable applications. This paper describes efficient and effective Just-In-Time (JIT) compilation techniques to resolve actual deadlock occurrences, which are signaled as runtime exceptions. Specifically, the techniques include inferring relevant program code from detected deadlocks, analyzing program code to determine appropriate resolution actions, generating deadlock resolution code according to resolution actions, dynamically installing reusable and assessable exception handlers which execute deadlock resolution code, and selectively preventing deadlocks of the same pattern in future.