I have the following code:
public void run() {
while (true) {
m = q.poll();
if (m != null) {
kf.sendMessage(m.topic, m.message);
}
}
}
where q is ConcurrentLinkedQueue. This currently makes up 100% of my processor. Is there a more efficient way to wait in a non-blocking queue? I prefer to use a non-blocking queue because I expect packet traffic from manufacturers in the queue, so I want to maximize performance. Is there a way to give up processor control for my thread if q.poll () returns null?
I have the opportunity to switch to a blocking queue, but I am curious how to do it right.
Change - a lot of good reviews! Thank you for your help. For the moment, I'm going to just switch to the linked block, and if I start to overestimate the performance issues.