Deadlock is notoriously difficult to detect and fix correctly. Existing approaches aim at fixing deadlocks under the premise of having known the deadlock and the buggy code involved in the deadlock, which leads to a certain gap from the practical multithreaded software development. In this paper, we describe the design and implementation of TDFix, which can detect, localize, and fix deadlocks in Java programs based on the pre-defined deadlock fixing templates. TDFix locates the buggy code by searching for the destination node in the AST of a program and modifying the node information based on the templates. Experimental results show that TDFix can successfully fix 176 out of 198 deadlocks in at most 90 seconds for each large Java project, indicating its effectiveness and efficiency.