练习代码

1.DeadThread 死锁

public class DeadThread {

    private static Object monitorA = new Object();

    private static Object monitorB = new Object();

    public static void main(String[] args) {
        Thread threadA = new Thread(new Runnable() {
            @Override
            public void run()   {
                synchronized(monitorA) {
                    System.out.println("线程A获取已获取锁A");
                    try {
                        Thread.sleep(100);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }

                    System.out.println("线程A准备获取锁B");
                    synchronized(monitorB) {
                        System.out.println("线程A已经获取锁B");
                    }
                }
                System.out.println("线程A run方法结束");
            }
        });

        Thread threadB = new Thread(new Runnable() {
            @Override
            public void run()   {
                synchronized(monitorB) {
                    System.out.println("线程B获取已获取锁B");
                    try {
                        Thread.sleep(100);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }

                    System.out.println("线程B准备获取锁A");
                    synchronized(monitorA) {
                        System.out.println("线程B已经获取锁A");
                    }
                }
                System.out.println("线程B run方法结束");
            }
        });

        threadA.start();
        threadB.start();
    }
}

2.排序 2分排序

 

2.动态规划算法

https://blog.csdn.net/u013309870/article/details/75193592

 

posted @ 2019-07-17 17:57  java.matt  阅读(210)  评论(0编辑  收藏  举报