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

Gallatin 21V 186 Reputation points
2023-12-04T03:58:34.35+00:00

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] o.h.b.s.app.service.impl.JobRunnable     : 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.support.JmsUtils.convertJmsAccessException(JmsUtils.java:311)
	at org.springframework.jms.support.JmsAccessor.convertJmsAccessException(JmsAccessor.java:185)
	at org.springframework.jms.core.JmsTemplate.execute(JmsTemplate.java:507)
	at org.springframework.jms.core.JmsTemplate.send(JmsTemplate.java:584)
	at org.springframework.jms.core.JmsTemplate.convertAndSend(JmsTemplate.java:661)
	at org.boogoo.attendance.infra.job.SyncPunchFromWeComJob.lambda$invoke$0(SyncPunchFromWeComJob.java:259)
	at java.base/java.util.ArrayList$ArrayListSpliterator.forEachRemaining(ArrayList.java:1625)
	at java.base/java.util.stream.ReferencePipeline$Head.forEach(ReferencePipeline.java:762)
	at org.boogoo.attendance.infra.job.SyncPunchFromWeComJob.invoke(SyncPunchFromWeComJob.java:257)
	at org.boogoo.attendance.infra.job.SyncPunchFromWeComJob.execute(SyncPunchFromWeComJob.java:175)
	at org.hzero.boot.scheduler.app.service.impl.JobRunnable.jobRun(JobRunnable.java:141)
	at org.hzero.boot.scheduler.app.service.impl.JobRunnable.run(JobRunnable.java:112)
	at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1136)
	at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635)
	at java.base/java.lang.Thread.run(Thread.java:833)
Caused by: javax.jms.JMSException: Error while attempting to add new Connection to the pool
	at org.messaginghub.pooled.jms.util.JMSExceptionSupport.create(JMSExceptionSupport.java:82)
	at org.messaginghub.pooled.jms.JmsPoolConnectionFactory.createJmsPoolConnection(JmsPoolConnectionFactory.java:719)
	at org.messaginghub.pooled.jms.JmsPoolConnectionFactory.createConnection(JmsPoolConnectionFactory.java:247)
	at org.messaginghub.pooled.jms.JmsPoolConnectionFactory.createConnection(JmsPoolConnectionFactory.java:242)
	at org.springframework.jms.support.JmsAccessor.createConnection(JmsAccessor.java:196)
	at org.springframework.jms.core.JmsTemplate.execute(JmsTemplate.java:494)
	... 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(JmsPoolConnectionFactory.java:717)
	... 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
    2023-12-12T16:47:10.7166667+00:00

    @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.

    https://learn.microsoft.com/en-us/azure/developer/java/spring-framework/configuration-properties-azure-service-bus-jms

    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