This week's book giveaway is in the Java 8 forum.
We're giving away four copies of Java 8 in Action and have Raoul-Gabriel Urma, Mario Fusco, and Alan Mycroft on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes OutOfMemoryError Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "OutOfMemoryError " Watch "OutOfMemoryError " New topic


kri shan
Ranch Hand

Joined: Apr 08, 2004
Posts: 1368
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

Joined: Aug 07, 2003
Posts: 1646
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?
I agree. Here's the link:
subject: OutOfMemoryError
Similar Threads
MDB: Message id is null Error
JMS question
JMS Queue : Log4j Warning
JMS on JBOSS- Asynchronous Queue Receiver
JMS Queue Issue