LOST messages
I have 2 queues (A and B) which would hold incoming messages, to save time I would only write these messages when the queue is at the capacity of 1000. When queue A is full, then the messages would be store in queue B and the messages in queue A would get flush out.
if ((queueA.size() < 1000) && (queueB.size() == 0)
queueA.add(message)
else if ((queueA.size() == 0) && (queueB.size() < 1000))
queueB.add(message)
else if (queueA.size >= 1000)
queueB.add(message)
flush(queueA)
else if (queueB.size() >= 1000)
queueA.add(message)
flush(queueB)
The problem occur when there is 1000 messages store in the queue and no other incoming message, then these 1000 messages would be lost. Can anybody help?
[801 byte] By [
mpanga] at [2007-10-3 3:56:32]

originally it was only a simple if....else....
if (queueA is full)
write to queueB
else
write to queueA
but since I would flush out everything in queueA when it's full, the next incoming message would immediately start to write to queueA again. Since i want to perserve the order, I would want the incoming messages continue to store in queueB until it's full.
As for the left over, I would perform some stat calculation at a certain time (say 00:00), if at 00:00, the timer doesn't go off, there would still be X number of messages in there, wouldn't it?
mpanga at 2007-7-14 21:54:45 >

This is what I meant.
//List activeQueue;
//List passiveQueue;
if (isFull(activeQueue)) {
List tmp = activeQueue;
activeQueue = passiveQueue;
passiveQueue = tmp;
flush(passiveQueue);
}
activeQueue.add(message);
Kaj
kajbja at 2007-7-14 21:54:45 >

> As for the left over, I would perform some stat> calculation at a certain time (say 00:00), if at> 00:00, the timer doesn't go off, there would still be> X number of messages in there, wouldn't it?Why wouldn't the timer go off?
kajbja at 2007-7-14 21:54:45 >

according to the codes given by kajbj, what if there are more than 1 messages arrive when activeQueue 1 message from being full? I don't get how the following codes would work for concurrency, and exactly when messages would start to write to the passiveQueue? Thanks
//List activeQueue;
//List passiveQueue;
if (isFull(activeQueue)) {
List tmp = activeQueue;
activeQueue = passiveQueue;
passiveQueue = tmp;
flush(passiveQueue);
}
activeQueue.add(message);
mpanga at 2007-7-14 21:54:45 >

> according to the codes given by kajbj, what if there
> are more than 1 messages arrive when activeQueue 1
> message from being full? I don't get how the
> following codes would work for concurrency, and
> exactly when messages would start to write to the
> passiveQueue? Thanks
You just need to synchronize the code.
Kaj
kajbja at 2007-7-14 21:54:45 >
