Javaを習いたての初心者です。
その中でメッセージキューの処理にてついて学習しているのですが、そこでAとBのオブジェクトがプロキシオブジェクトを介して通信するプログラムを作ろうとしているのですが、どのようにしていけばわからないので教えていただきたいです。
この課題を取り組む前に複数メッセージを蓄えるキューの作成はしました。
コードを以下に示します。
class Queue { public static void main(String[] args){} private String[] buf; private int messagein = 0; int start = 0; public Queue(int size) { buf = new String[size]; } public synchronized void wrtMessage(String str) throws InterruptedException { while (messagein >= buf.length) { wait(); } int end = (start+messagein)% buf.length; buf[end]=str; messagein++; notifyAll(); } public synchronized String readMessage() throws InterruptedException { while(messagein == 0) { wait(); } String mes = buf[start]; start=(start+1)%buf.length; messagein--; notifyAll(); return mes; } }
ここからどう改良していけばよいでしょうか。
よろしくお願いいたします。
マークダウンが中途半端になっています。
コード全体を```で囲ってください。

あなたの回答
tips
プレビュー