Java – the strict order in which messages are processed concurrently

In my Java EE web application, I need to strictly process incoming mail in the order of arrival I assume that my webapp container (Tomcat 6) preserves the order of messages when messages arrive at the HTTP port

The headache is the way I process this information internally In order to improve the workload, I attach the processing of each message to the ThreadPool, because there are many things to be done here XML parsing, sometimes using external web services to enrich data After processing, I push the Java representation of the message to a complex stream processing engine esper codehaus. Org, which is thread safe Here, different modes are examined, where the entry order is the highest requirement, for example, the threshold of the phenomenon exceeds

I want to insert each processed message into the PriorityQueue and receive a priority ID when it arrives (in my servlet, each message is incremented) The problem is as follows:

Inserting a thread that polls an element from the queue (the lowest ID is the head of the queue) into esper may skip an ID because it does not check for missing items I think an illustration is better:

For steps (1) to (4), everything works as expected However, in step (5), queuepoller retrieves element 6 instead of element 4 (inserted later in step (6)) This results in message order: 2; 3; 6; four

What I'm trying to do is change the header of the polling queue to follow the implementation of strict ID order This means that if the element of the next ID has not been inserted into the queue, wait until it is inserted This seems to work for the first 10 minutes, but then hangs, possibly because an element is not inserted into the queue

Anyone who has a similar problem in the past has some tips for me?

Solution

View disruptor – high performance queue of strict orders (first in preference)

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>