Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

OutOfMemoryError

 
kri shan
Ranch Hand
Posts: 1473
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I got this code from net and i did some midification. After sending 68 messages it gives java.lang.OutOfMemoryError. Why??? I tested many times. Same problem comes.

 
David Harkness
Ranch Hand
Posts: 1646
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
After a quick glance, it seems you are creating all of the objects (Context, Connection, QueueSession, MessageListener, and QueueSender) each time you send a message. Instead, create each of those once and reuse them. Perhaps you might want to split initialization and sending messages into different methods, and not have the send method call the init method.

Also, your SendRecvClient extends Thread but you never start it. Does it even need to be a Thread at all?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic