java.lang.NullPointerException: Cannot invoke "org.messaginghub.pooled.jms.pool.PooledConnection.incrementReferenceCount()" because "connection" is null

Gallatin 21V 186 Reputation points

we're using JMS in Spring to access Azure Service Bus in our application, when we set spring.jms.servicebus.pool.max-connections to 100, our application met a error like below, after we changed it to be 50, our application started working, so I'm wondering if 100 exceeds the upper limit of spring.jms.servicebus.pool.max-connections, if so, what's the recommended number for it?

[scheduler-job-run-4]     : org.springframework.jms.UncategorizedJmsException: Uncategorized exception occurred during JMS processing; nested exception is javax.jms.JMSException: Error while attempting to add new Connection to the pool; nested exception is java.lang.NullPointerException: Cannot invoke "org.messaginghub.pooled.jms.pool.PooledConnection.incrementReferenceCount()" because "connection" is null
	at org.springframework.jms.core.JmsTemplate.execute(
	at org.springframework.jms.core.JmsTemplate.send(
	at org.springframework.jms.core.JmsTemplate.convertAndSend(
	at org.boogoo.attendance.infra.job.SyncPunchFromWeComJob.lambda$invoke$0(
	at java.base/java.util.ArrayList$ArrayListSpliterator.forEachRemaining(
	at java.base/$Head.forEach(
	at org.boogoo.attendance.infra.job.SyncPunchFromWeComJob.invoke(
	at org.boogoo.attendance.infra.job.SyncPunchFromWeComJob.execute(
	at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(
	at java.base/java.util.concurrent.ThreadPoolExecutor$
	at java.base/
Caused by: javax.jms.JMSException: Error while attempting to add new Connection to the pool
	at org.messaginghub.pooled.jms.util.JMSExceptionSupport.create(
	at org.messaginghub.pooled.jms.JmsPoolConnectionFactory.createJmsPoolConnection(
	at org.messaginghub.pooled.jms.JmsPoolConnectionFactory.createConnection(
	at org.messaginghub.pooled.jms.JmsPoolConnectionFactory.createConnection(
	at org.springframework.jms.core.JmsTemplate.execute(
	... 12 more
Caused by: java.lang.NullPointerException: Cannot invoke "org.messaginghub.pooled.jms.pool.PooledConnection.incrementReferenceCount()" because "connection" is null
	at org.messaginghub.pooled.jms.JmsPoolConnectionFactory.createJmsPoolConnection(
	... 16 more
Azure Service Bus
Azure Service Bus
An Azure service that provides cloud messaging as a service and hybrid integration.
584 questions
{count} votes

1 answer

Sort by: Most helpful
  1. JananiRamesh-MSFT 23,486 Reputation points

    @Gallatin 21V Thanks for reaching out. The error indicates that the application was trying to add a new connection to the pool, but the connection was null. This could indeed be due to the pool reaching its maximum capacity, which is determined by the spring.jms.servicebus.pool.max-connections property.

    The maximum value for this property can depend on various factors such as the application’s workload, the number of concurrent users, and the available system resources. Therefore, it's recommended to perform load testing to determine the optimal value.

    Please let me know if you have any further queries. I would be happy to assist you.

    0 comments No comments