I found a bad error: queue overflow, no 281 lenth = 2b8c, can you help me?

G

greatwall

Develop envioronment: jbuilder 2006

recently I did a producor and cosumer program, the producor produce
msgItem and the consumer consume the msgItem. But when I run the
program, I found the following error, can somebody help me?


code segments:
public void run() {
Timer timer = new Timer();
timer.schedule(new TimerTask() {
public void run() {
if (getReadyFlag()) {
//can read data
StreamQueue.AppendMessage(new
ByteQueueItem(getStreamBytes()));
setReadyFlag();
}
}
}, 10, 1);
// throw new java.lang.UnsupportedOperationException(
// "Method run() not yet implemented.");
}


error when running:

queue overflow, no 281 lenth = 2b8c
queue overflow, no 284 lenth = 26fc
queue overflow, no 291 lenth = 2e24
queue overflow, no 294 lenth = 2d48
queue overflow, no 297 lenth = 2b38
queue overflow, no 300 lenth = 2690
queue overflow, no 303 lenth = 26a4
queue overflow, no 306 lenth = 28a4
queue overflow, no 316 lenth = 2570
queue overflow, no 319 lenth = 147c
queue overflow, no 325 lenth = 2544
queue overflow, no 328 lenth = 27a4
queue overflow, no 331 lenth = 1548


Do somebody know how this error happen???
 
P

Philipp Leitner

Since StreamQueue does not seem to be part of the standard Java libs you
should tell us what library this class refers to.

But if I was you I would look at what the maximum size of this queue is,
and how you could increase it, since it definitely looks like your queue
is simply overflowing :)

/philipp
 
G

Guest

Following is the code of the class Queue, but I think this error is not
caused by this Queue.


////////////////////////////////////////////////////////////////////////////////////////
import java.lang.InterruptedException;

abstract class QueueItem
{
protected QueueItem Next;
public QueueItem() {
Next = null;
}
}
class ByteQueueItem extends QueueItem
{
byte[] bArray;
int len;
public ByteQueueItem(byte[] buff) {
len = buff.length;
bArray = new byte[len];
for (int i = 0; i < len; i++) {
bArray = buff;
}
}

public byte[] getBArray() {
return bArray;
}

public int getLen() {
return len;
}
}


public class Queue {
public Queue() {
QueueHead = null;
}

private QueueItem QueueHead;
static int count = 0;

protected synchronized QueueItem GetMessage() {
while (count == 0) {
try {
this.wait();
} catch (InterruptedException e) {
System.out.println("ERROR In GetMessage--" +
e.toString());
}
}
this.notify();
if (QueueHead != null) {
QueueItem msgItem = QueueHead;
QueueHead = QueueHead.Next;
msgItem.Next = null;
count--;
return msgItem;
}
return null;
}

synchronized void AppendMessage(QueueItem msgItem) {
while (count >= 100000) {
try {
this.wait();
} catch (InterruptedException e) {
System.out.println("ERROR in AppendMessage" +
e.toString());
}
}
this.notify();
if (QueueHead == null) {
QueueHead = msgItem;
count = 1;
} else {
QueueItem Last;
Last = QueueHead;
while (Last.Next != null)
Last = Last.Next;
Last.Next = msgItem;
count++;
}
msgItem.Next = null;
}
}
//////////////////////////////////////////////////////////////////////

I use this Queue in a thread, which like this, following is the
implementation of the run method of the thread

public void run() {
Timer timer = new Timer();
timer.schedule(new TimerTask() {
public void run() {
if (getReadyFlag()) {
StreamQueue.AppendMessage(new
ByteQueueItem(getStreamBytes()));

setReadyFlag();
}
}
}, 1000, 1);
//throw new java.lang.UnsupportedOperationException(
// "Method run() not yet implemented.");
}
 
C

Chris Smith

greatwall said:
recently I did a producor and cosumer program, the producor produce
msgItem and the consumer consume the msgItem. But when I run the
program, I found the following error, can somebody help me?

Perhaps we could, if you would provide enough information to do so. As
it is, though, we see only a class called StreamQueue that's not in the
standard library, some methods called getReadyFlag and setReadyFlag
which don't seem to come with an implementation, and the code for only
one side of the producer/consumer pair (I can't even tell which side it
is, which is NOT a good sign). None of the above contains any of your
thread synchronization primitives at all, so I don't know how you
thought we would find your problem.

It does look like something is wrong with the synchronization here,
since you don't have kind of protection to ensure that the sequence
"getReadyFlag()" -> "StreamQueue.AppendMessage" is relatively atomic to
anything else in your code. In other words, it's possible that you
check the ststus of the "ready flag" (whatever that is), and then some
other thread interrupts and changes it, and THEN you call AppendMessage.
If AppendMessage depends on the return value of getReadyFlag() being
true, then this is broken.

For more help, please create and post real, compileable sample code to
demonstrate your problem. And if it's up to you, please rename
AppendMessage to appendMessage. In Java, method names start with lower-
case characters.

--
www.designacourse.com
The Easiest Way To Train Anyone... Anywhere.

Chris Smith - Lead Software Developer/Technical Trainer
MindIQ Corporation
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top