微信證件 OCR 能力升級:支援最新銀行卡版式,可同時識別身份證正反面
阿新 • • 發佈:2020-10-01
概述
互相要對方正在佔有的鎖,導致卡住不動
例項
/** * 死鎖 */ public class TestDeadLock { public static void main(String[] args) { new MakeUp(0,"嘟嘟").start(); new MakeUp(1,"dudu").start(); } } //鏡子 class Mirror{ } //口紅 class Lipstick{ } //化妝 class MakeUp extends Thread{ static Mirror mirror = new Mirror(); static Lipstick lipstick = new Lipstick(); private int select; private String name; public MakeUp(int select, String name) { this.select = select; this.name = name; } @Override public void run() { try { makeup(); } catch (InterruptedException e) { e.printStackTrace(); } } public void makeup() throws InterruptedException { if(select == 0){ synchronized (mirror){ System.out.println(this.name+ " 獲得了鏡子的鎖"); Thread.sleep(2000); synchronized (lipstick){ System.out.println(this.name + " 獲得了口紅的鎖"); } } }else{ synchronized (lipstick){ System.out.println(this.name + " 獲得了口紅的鎖"); Thread.sleep(2000); synchronized (mirror){ System.out.println(this.name+ " 獲得了鏡子的鎖"); } } } }