Demo11_DeadLock.java 817 B

12345678910111213141516171819202122232425262728293031323334
  1. package J20250730;
  2. /**
  3. * @author WanJl
  4. * @version 1.0
  5. * @title Demo11_DeadLock
  6. * @description
  7. * @create 2025/7/30
  8. */
  9. public class Demo11_DeadLock {
  10. public static void main(String[] args) {
  11. Object o1=new Object();
  12. Object o2=new Object();
  13. new Thread(()->{
  14. while (true){
  15. synchronized (o1){
  16. synchronized (o2){
  17. System.out.println("线程1........");
  18. }
  19. }
  20. }
  21. },"线程1").start();
  22. new Thread(()->{
  23. while (true){
  24. synchronized (o2){
  25. synchronized (o1){
  26. System.out.println("线程2........");
  27. }
  28. }
  29. }
  30. },"线程2").start();
  31. }
  32. }