I have several threads, each of which has its own private parallel queue, and everything that they do starts an infinite loop, receiving messages from it. It may happen that one of the queues will not receive messages for a certain period of time (maybe a couple of seconds), and they can also be in large packets and fast processing is required.
I would like to know what would be most appropriate to do in the first case: use a blocking queue and block the thread until I have no more input or Thread.yield ()?
I want to have as many CPU resources as possible at a given time, since the number of parallel threads can increase over time, but I also do not want message processing to lag, because there is no guarantee when the thread will be redistributed for execution when yield () is executed. I know that hardware, operating system and other factors play an important role here, but putting that aside and looking at it from the point of view of Java (JVM?), What would be the most optimal?
java multithreading concurrency
teto
source share