Queue and memory leaks
andrewdem Apr 21, 2003 5:40 AMHi, All
I have a problem with memory leaks when
using queue in my application.
The application works on JBoss 3.2.0 RC4 (jdk 1.4.1_02) and Red Hat Linux 7.3
and using: Filters, Servlets, Queues, MDB.
Servlet sends messages to queue which will process by MDB.
All messages processed by MDB.
I've detected (with Optimizeit Profiler 5.0) that
char[] most of all allocates heap memory.
char[] generates by
org.apache.log4j.CategoryKey() 26.6% (54874 items)
org.jboss.mq.server.ClientConsumer() 26.54% (54744 items)
org.jboss.mq.server.ClientConsumer() called from org.jboss.connection.Start()
(which called from RequestBroker servlet).
I've closed queue connections in RequestBroker (see source code follow),
call gc every 5 min, but JVM allocating memory increase every hour.
After 10 min from start application server JVM allocates about 120M of memory (heap: 30M/22M),
but in 3-4 days JVM allocate 707M of memory (heap: 104M/56M).
Every day system is low-activity about 10 hours.
Once I set Xmx=128M and in one week JVM has crushed with OutOfMemory error.
This system is not a big and comparatively not very active,
but needs amount of memory ?!
See bellow servlet (RequestBroker) that sends messages in queue
and fragments of jboss conf. files.
Can you advice to me anything to solve this problem?
Thanks in advance.
================ RequestBroker (servlet) ====================
<...>
public class RequestBroker extends HttpServlet
{
public void doPost(
<...>
{
<...> QueueConnection con = null;
QueueSender sender = null;
Context ctx = null;
QueueConnectionFactory qcf = null;
QueueSession session = null;
Queue queue = null;
xerces parser = null;
<..>
parser = new xerces();
Document document = null;
try
{
document = parser.parse(new InputSource(in));
<...>
}
msgObject new_msg = null;
ObjectMessage obj_msg = null;
try
{
//Setup queue
ctx = new InitialContext();
qcf =(QueueConnectionFactory) ctx.lookup("queue1"));
con = qcf.createQueueConnection();
session =con.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
queue = (Queue) ctx.lookup(lp.getProperty("queue.mess_to_cpa"));
con.start();
sender = session.createSender(queue);
log.debug("Queue setup finished");
// Çäåñü ðàçîáðàííûé xml ñêëàäûâàåòñÿ â î÷åðåäü êàê DOM Object
new_msg = new msgObject(document);
obj_msg = session.createObjectMessage(new_msg);
obj_msg.setStringProperty("åå", rr);
sender.send(obj_msg);
} catch (Exception e)
<...>
} finally
{
try
{
con.close();
con = null;
session.close();
session = null;
sender.close();
sender = null;
log.debug("Queue connection closed");
} catch (Exception ee1)
{
log.error("Can not clolse queue connection!");
} //try
qcf = null;
queue = null;
} //try
============= msgObject ==================================
public class msgObject implements Serializable
{
private Document doc;
public msgObject(Document doc)
{
this.doc = doc;
}
public msgObject()
{
this.doc = null;
}
public void setDocument(Document doc)
{
this.doc = doc;
}
public Document getDocument()
{
return this.doc;
}
};
================ jbossmq-service.xml =================
<depends optional-attribute-name="Invoker">jboss.mq:service=Invoker
ConnectionFactory
XAConnectionFactory
0
<depends optional-attribute-name="Invoker">jboss.mq:service=Invoker
RMIConnectionFactory
RMIXAConnectionFactory
60000
<depends optional-attribute-name="Invoker">jboss.mq:service=Invoker
java:/ConnectionFactory
java:/XAConnectionFactory
9097
60000
true
<..>
100
150
<!--
<depends optional-attribute-name="CacheStore">jboss.mq:service=CacheStore
-->
jboss.mq:service=PersistenceManager
<...>
=============== jms-service.xml ==========================
<!-- The server session pool for Message Driven Beans -->
<depends optional-attribute-name="XidFactory">jboss:service=XidFactory
StdJMSPool
org.jboss.jms.asf.StdServerSessionPoolFactory
======= ejb-jar.xml (äëÿ MDB) =======================
<...>
<message-driven>
MDB1
<ejb-name>MDB1</ejb-name>
<ejb-class>test.MDB1</ejb-class>
<transaction-type>Container</transaction-type>
<acknowledge-mode>Auto-acknowledge</acknowledge-mode>
<message-driven-destination>
<destination-type>javax.jms.Queue</destination-type>
<subscription-durability>NonDurable</subscription-durability>
</message-driven-destination>
<..>
======= jboss.xml =================================
<enterprise-beans>
<message-driven>
<ejb-name>MDB1</ejb-name>
<destination-jndi-name>queue/queue1</destination-jndi-name>
<resource-ref>
<res-ref-name>ConnectionFactory</res-ref-name>
<jndi-name>ConnectionFactory</jndi-name>
</resource-ref>
<resource-ref>
<res-ref-name>XAConnectionFactory</res-ref-name>
<jndi-name>XAConnectionFactory</jndi-name>
</resource-ref>
</message-driven>
</enterprise-beans>
=======================================================
--
Best regards,
Andrey Demchenko.