java-同步锁和读写锁

同步锁

《java-同步锁和读写锁》
《java-同步锁和读写锁》

convert = new Thread(){
            public void run() {
                synchronized (LOCK) {
                    while (true) {
                        try {
                            //doconvert();
                        } catch (ExceptionAbstract e1) {
                            e1.printStackTrace();
                            logger.error("线程1异常,唤醒。。");
                            notifyAll();
                        }
                        if(!flag){
                            flag = true;
                            LOCK.notify();
                                try {
                                    LOCK.wait();
                                    Thread.sleep(5000);
                                } catch (InterruptedException e) {
                                    e.printStackTrace();
                                }
                        }
                    }
                }
            }
    };
    send = new Thread(){
            public void run() {
                synchronized (LOCK) {
                    while (true) {
                        try {
                            dosend();
                        } catch (ExceptionAbstract e1) {
                            e1.printStackTrace();
                            logger.error("线程1异常,唤醒。。");
                            notifyAll();
                        }
                        
                        if(flag){
                            flag = false;
                            LOCK.notify();
                                try {
                                    LOCK.wait();
                                    Thread.sleep(5000);
                                } catch (InterruptedException e) {
                                    e.printStackTrace();
                                }
                        }
                    }
                }
            }
    };
            //convert.start();
            try {
                Thread.sleep(20000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            send.start();

View Code

读写锁

    原文作者:琦琦狐
    原文地址: http://www.cnblogs.com/samelove/p/3418861.html
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞