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();
读写锁