'Sending a Packet to a Number of Threads?
I have a central information source (architecturally) and need some way to send the packet to each thread which does a fast operation and then waits for a new packet afterwards.
I'm weighing the pros and cons of a distributed system, as opposed to a hierarchical system.
I could give each thread its own BlockingQueue, but then I would have to:
a) make a blocking queue each class, and then make sure that it is populated from the central packet source (which I could automate with a method to do such a thing).
Or the central queue method would be something like:
A child class of blocking queue whose take method:
var result = topOfQueue //wait on countdown latch static variable for ~7 threads //latch released, immediatly wait on cyclic barrier for 8 threads (7 + 1 thread which is removes the topmost queue element then joins the barrierthe cyclic barrier). return result;
Is this a good architecture given my objectives of sharing the packet with each thread? Or is there a far more efficient architecture that I'm missing (or a class that already exists for this?)
Which would scale better?
Solution 1:[1]
I would start with something simple like an Executor. It manages a bunch of threads that receive work through a shared queue.
Also, I would set a set of (micro) benchmarks to confirm your design choices.
[edit] Or do you need to packet to be processed by every thread? In that case, you could make a set of single-threaded executors and copy the packet to each executor.
These are just some suggestions on how to go about it. I have no clue of this is a proper solution in your design.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 |
