I have two threads: one that sends messages, and the other that analyzes them. Simple, general. I use ArrayBlockingQueue for synchronization, but I do not want the dispatcher to directly access the work message queue - I use the shell. The question is whether the installer should declare synchronized .
public class Worker implements Runnable{ protected final ArrayBlockingQueue<ByteBuffer> messages = new ArrayBlockingQueue<ByteBuffer>(16); public synchronized void putMessage(ByteBuffer msg) throws InterruptedException{ messages.put(ByteBuffer); } }
source share