I am using GlassFish JMS ConnectionFactory. Connection is closed in finally. and Maximum Pool Size is set to 5.
Test Case: I sent 10 messages constantly within 3 seconds from invoker().
Result: First 5 messages sent successfully and message 6 onward failed to allocate more connections. It means all previous 5 connections were still open.
Question 1: How long does it take to release the connection poll after connection.close()?
Question 2: Is the Garbage collector responsible to release the connection after JMS connection.close()?
This is my simple message client which sends messages to the queue
private void invoker(String id){
Connection connection = null;
Session session = null;
MessageProducer messageProducer = null;
TextMessage message = null;
try {
connection = connectionFactory.createConnection();
session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
messageProducer = session.createProducer(successfulQueue);
String msg = id;
message = session.createTextMessage(msg);
messageProducer.send(message);
log.info("Successful message is Sent to ProcessQueue: [" + msg + "]");
}
catch (Exception e) {
log.error(e);
}
finally {
if (messageProducer != null) {
try {
messageProducer.close();
}
catch (JMSException e) {
log.error(e);
}
}
if (session != null) {
try {
session.close();
}
catch (JMSException e) {
log.error(e);
}
}
if (connection != null) {
try {
connection.close();
}
catch (JMSException e) {
log.error(e);
}
}
}
Garbage Collector
not theJMS Connection Releaser
, so take a guess. – KayamanMDB
, which is wrong. A Message Driven Bean is executed to handle a message. Your code isn't handling messages, it's sends a message. – Kayaman