Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / May 2006

Tip: Looking for answers? Try searching our database.

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

Thread view: 
greatwall - 27 May 2006 07:46 GMT
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???
Philipp Leitner - 27 May 2006 10:30 GMT
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

greatwall schrieb:
> Develop envioronment: jbuilder 2006
>
[quoted text clipped - 36 lines]
>
> Do somebody know how this error happen???
快乐至上 - 27 May 2006 15:56 GMT
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[i] = buff[i];
       }
   }

   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.");
   }
Chris Smith - 27 May 2006 20:04 GMT
> 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.

Signature

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

Chris Smith - Lead Software Developer/Technical Trainer
MindIQ Corporation



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.