Package namespace; Class dead implements runnable {public Boolean flag; public object Locka = new object (); Public object lockb = new object (); Public dead (Boolean f) {This. flag = f;} public void run () {While (true) {If (FLAG) {synchronized (lock. locka) {system. out. println ("If loca"); synchronized (lock. lockb) {system. out. println ("If lockb") ;}} else {synchronized (lock. lockb) {system. out. println ("else lockb"); synchronized (lock. locka) {system. out. println ("else Locka") ;}}}} class lock {static object Locka = new object (); static object lockb = new object ();} public class deadlock {public static void main (string ARGs []) {thread T1 = new thread (new dead (true )); thread t2 = new thread (new dead (false); t1.start (); t2.start () ;}}/** write a deadlock Program * The cause is that the two locks are not referenced in the same lock, which will lead to deadlocks. ** when there are many security problems in the current situation, consider the following: * 1. is there two threads, and there is no synchronization between the two threads, that is, there is no synchronized block or function * 2. if multiple syncs exist Code If the block or synchronous function is used, check whether all the synchronization functions use the same lock. If not, the deadlock and security problems may occur. ***/15:13:46