package chatRoom; import java.util.ArrayList; public class MultiQueue { public ArrayList buffer = new ArrayList(); public synchronized void put(String message, int clientId) { buffer.add(new MultiMessage(message, clientId)); notify(); } public synchronized MultiMessage take() { MultiMessage message = null; while(buffer.size() == 0) { try { wait(); } catch (InterruptedException e) { e.printStackTrace(); } } if(buffer.size()>0){ message = buffer.get(0); buffer.remove(0); } return message; } }