執行main方法之后控制臺打印內容如下:
thread1 get locka ing!
thread2 get lockb ing!
thread1 after sleep 500ms!
thread1 need lockb!Just waiting!
thread2 after sleep 500ms!
thread2 need locka! Just waiting!
thread1 need lockb!Just waiting!表明thread1線(xiàn)程進(jìn)入死鎖等待lockb釋放。
thread2 need locka! Just waiting! 表明thread2線(xiàn)程進(jìn)入死鎖等待locka釋放。
第二種concurrent包Lock錯誤使用,導致死鎖:
lock.unlock();釋放鎖使用地方不規范,導致死鎖不能正常釋放!
聯(lián)系客服