@@ -0,0 +1,2484 @@
+package com.njust.test.learn;%0A%0Aimport java.text.SimpleDateFormat;%0Aimport java.util.Date;%0Aimport java.util.Random;%0Aimport java.util.concurrent.locks.ReadWriteLock;%0Aimport java.util.concurrent.locks.ReentrantReadWriteLock;%0A%0Apublic class ReadWriteLockDemo%0A%7B%0A    public static void main(String%5B%5D args)%0A    %7B%0A        ShareData shareData = new ShareData();%0A        %0A        for (int i = 0; i %3C 3; i++)%0A        %7B%0A            new Thread(() -%3E %7B%0A                while (true)%0A                %7B%0A                    shareData.readData();%0A                %7D%0A            %7D).start();%0A        %7D%0A        for (int i = 0; i %3C 3; i++)%0A        %7B%0A            new Thread(() -%3E %7B%0A                while (true)%0A                %7B%0A                    shareData.writeData(%22%22 + new Random().nextInt(10000));%0A                %7D%0A            %7D).start();%0A        %7D%0A        %0A    %7D%0A    %0A    private static class ShareData%0A    %7B%0A        private ReadWriteLock readWriteLock = new ReentrantReadWriteLock();%0A        %0A        private String data;%0A        %0A        private void readData()%0A        %7B%0A            //%E8%AF%BBlock%0A            readWriteLock.readLock().lock();%0A            %0A            printLog(%22 ===%3E try to read%22);%0A            try%0A            %7B%0A                Thread.sleep(2000);%0A                printLog(%22 %3C=== end to read:%22 + this.data);%0A            %7D%0A            catch (Exception e)%0A            %7B%0A                e.printStackTrace();%0A            %7D%0A            finally%0A            %7B%0A                //%E8%AF%BBunlock%0A                readWriteLock.readLock().unlock();%0A            %7D%0A        %7D%0A        %0A        private void writeData(String data)%0A        %7B%0A            //%E5%86%99lock%0A            readWriteLock.writeLock().lock();%0A            %0A            printLog(%22 ===%3E try to write%22);%0A            try%0A            %7B%0A                Thread.sleep(2000);%0A                this.data = data;%0A                printLog(%22%3C=== end to write:%22 + data);%0A            %7D%0A            catch (Exception e)%0A            %7B%0A                e.printStackTrace();%0A            %7D%0A            finally%0A            %7B%0A                //%E5%86%99lock%0A                readWriteLock.writeLock().unlock();%0A            %7D%0A            %0A        %7D%0A        %0A        private void printLog(String msg)%0A        %7B%0A            SimpleDateFormat simpleDateFormat = new SimpleDateFormat(%22HH:mm:ss%22);%0A            String dateStr = simpleDateFormat.format(new Date());%0A            System.out.println(%22%5B%22 + dateStr + %22%5D %22 + Thread.currentThread().getName() + %22 %22 + msg);%0A        %7D%0A        %0A    %7D%0A%7D%0A

Create ReadWriteLockDemo.java