I was originally going to list arrays of nodes, but then I realized that all the nodes have to be there own thread.
You can store an array of flows, it will still maintain thread-per- node with the same logical structure.
how do I pass information back forward between threads in Java.
If the flows are in the same process, the sockets are definitely overkill. I would use one or more copies ConcurrentLinkedQueue input / off messages.
One or more really depends on what kind of communication you are doing. Maybe one ConcurrentLinkedQueue per node, so the nodes forward messages in the queue, and each node knows where the message comes from.
A few implementation tips
Complete all of the logic for routing messages in the class - let this class VirtualNetwork . VirtualNetwork deals with all instances ConcurrentLinkedQueue and offers API methods for all streams to send / receive messages. Make one copy of the class VirtualNetwork accessible to all nodes - passing reference to it in the Thread constructor.
This is a sketch of how it will look your class NodeThread . Please note that classes VirtualNetwork and Message - classes that you need to implement your own.
class NodeThread extends Thread { private int nodeId; private VirtualNetwork network; public NodeThread(int nodeId,VirtualNetwork network) { this.network = network; this.nodeId = nodeId; } public void run() { int nodeReceptor = this.nodeId -1; Message m = new Message(this.nodeId,nodeReceptor); m.setContent(10); network.send(m); Message m = network.receive(this.nodeId); } } ) { class NodeThread extends Thread { private int nodeId; private VirtualNetwork network; public NodeThread(int nodeId,VirtualNetwork network) { this.network = network; this.nodeId = nodeId; } public void run() { int nodeReceptor = this.nodeId -1; Message m = new Message(this.nodeId,nodeReceptor); m.setContent(10); network.send(m); Message m = network.receive(this.nodeId); } } * / class NodeThread extends Thread { private int nodeId; private VirtualNetwork network; public NodeThread(int nodeId,VirtualNetwork network) { this.network = network; this.nodeId = nodeId; } public void run() { int nodeReceptor = this.nodeId -1; Message m = new Message(this.nodeId,nodeReceptor); m.setContent(10); network.send(m); Message m = network.receive(this.nodeId); } } nodeReceptor); class NodeThread extends Thread { private int nodeId; private VirtualNetwork network; public NodeThread(int nodeId,VirtualNetwork network) { this.network = network; this.nodeId = nodeId; } public void run() { int nodeReceptor = this.nodeId -1; Message m = new Message(this.nodeId,nodeReceptor); m.setContent(10); network.send(m); Message m = network.receive(this.nodeId); } } / class NodeThread extends Thread { private int nodeId; private VirtualNetwork network; public NodeThread(int nodeId,VirtualNetwork network) { this.network = network; this.nodeId = nodeId; } public void run() { int nodeReceptor = this.nodeId -1; Message m = new Message(this.nodeId,nodeReceptor); m.setContent(10); network.send(m); Message m = network.receive(this.nodeId); } } in a blocking way or not * / class NodeThread extends Thread { private int nodeId; private VirtualNetwork network; public NodeThread(int nodeId,VirtualNetwork network) { this.network = network; this.nodeId = nodeId; } public void run() { int nodeReceptor = this.nodeId -1; Message m = new Message(this.nodeId,nodeReceptor); m.setContent(10); network.send(m); Message m = network.receive(this.nodeId); } }