I want to be able to create multiple threads and send data to a specific thread based on what the main program receives.
Basically I am sending a packet to a receiving program which will contain a number. This number is used to determine which thread it wants to communicate with. How can I send that packet to a thread with that same number?
Example: threads 1,2,3,4 and 5 exist. My main program receives a packet with the number 3. I want to send that packet to thread 3.
How can I achieve this?
Create a queue for each thread, and have each thread listen to that queue. Your main thread can then put data (or a "message") on each queue.
You'll just want to make sure that the queue structure you choose is safe for concurrent access (thread-safe). Something like a LinkedBlockingQueue should do nicely.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With