publicclassMain{publicstaticvoidmain(String[] args){
Data data =newData(10);newReaderThread(data).start();newReaderThread(data).start();newReaderThread(data).start();newReaderThread(data).start();newReaderThread(data).start();newReaderThread(data).start();newWriterThread(data,"ABCDEFGHIJKLMNOPQRSTUVWSYZ").start();newWriterThread(data,"abcdefghigklmnopqrstuvwsyz").start();}}
publicclassWriterThreadextendsThread{privatestaticfinal Random random =newRandom();privatefinal Data data;privatefinal String filler;privateint index =0;publicWriterThread(Data data,String filler){this.data = data;this.filler = filler;}publicvoidrun(){try{while(true){char c =nextchar();
data.write(c);
Thread.sleep(random.nextInt(3000));}}catch(InterruptedException e){
e.printStackTrace();}}privatecharnextchar(){char c = filler.charAt(index);
index++;if(index >= filler.length()){
index =0;}return c;}}
Data:public class Data { private final char[] buffer; private final ReadWriteLock lock = new ReadWriteLock(); public Data(int size){ this.buffer = new char[size]; Arrays.fill(buffer, '*'); } public char[] read() throw