when sending some messages via a MDB there are some warnings about unclosed JMS connections which then are closed by ActiveMQ. The MDB gets a messageHandler injected which gets a replysender injected whichs method is given below.
This is the warning I do get:
[org.apache.activemq.artemis.jms.client] (Finalizer) AMQ122000: I''m closing a JMS connection you left open. Please make sure you close all JMS connections explicitly before letting them go out of scope! see stacktrace to find out where it was created: java.lang.Exception
at org.apache.activemq.artemis.jms.client.ActiveMQConnection.<init>(ActiveMQConnection.java:155)
at org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory.createConnectionInternal(ActiveMQConnectionFactory.java:750)
at org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory.createConnection(ActiveMQConnectionFactory.java:233)
at org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory.createConnection(ActiveMQConnectionFactory.java:229)
[...]
The warning occurs (not every time) within the following code when the try-block has finished (so directly after log.debug(..)):
private Message doSendAndReturn(XmlMessageCreator messageCreator) throws JMSException {
Message message = null;
try (Session session = cf.createConnection().createSession(false, Session.AUTO_ACKNOWLEDGE);) {
MessageProducer producer = session.createProducer(jmsReplyQueue);
message = messageCreator.createMessage(session);
producer.send(message);
log.debug("JMSTemplate sended message to myEnvironment with ID "
+ message.getJMSMessageID()
+ "\n Using Thread "
+ Thread.currentThread().getName());
}
return message;
}
I still read that these warnings also occur when theres no reference to the connection factory but "cf" is a global singleton variable which is defined via the context:
@Resource(lookup = "java:/myProject_myEnvironment_factory")
private ConnectionFactory cf;
When setting a break-point on log.debug(...) I can see that it seems to work some times but sometimes not. This method is called about 7 times while the first three times work, then one time throws the warning four times (probably also for every previous call) and so on for a few times. This is reproducable every time I do a specific task within the webapp.
I do not know whats going wrong here.
Any advice would be grateful. Thanks in advance.
I think the problem is that although the session object is defined in the try-with-resource part but there is no explicit variable for the connection within the try-with-resource part.
After changing it from:
try (Session session = cf.createConnection().createSession(false, Session.AUTO_ACKNOWLEDGE);) {
to:
try (
Connection connection = cf.createConnection();
Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
) {
I am not getting the warnings any more. Thanks for listening.