ActiveMQ高并发发送消息异常解决方法
现象,使用10个线程每100ms发送一条消息,大约3000多条后,出现异常,所有线程停止:
javax.jms.JMSException: Could not connect to broker URL: tcp://localhost:61616. Reason: java.net.BindException: Address already in use: connect; nested exception is ja va.net.BindException: Address already in use: connect
原因:创建了太多jms连接没有来得及回收
解决方法:使用jms连接池
原来的配置:
<bean id="jndiTemplate" class="org.springframework.jndi.JndiTemplate"> <property name="environment"> <props> <prop key="java.naming.factory.initial"> org.apache.activemq.jndi.ActiveMQInitialContextFactory </prop> <prop key="java.naming.provider.url"> tcp://huzq-linux:61616 </prop> </props> </property> </bean> <bean id="jndiConnectionFactory" class="org.springframework.jndi.JndiObjectFactoryBean"> <property name="jndiName"> <value>ConnectionFactory</value> </property> <property name="jndiTemplate"> <ref local="jndiTemplate"></ref> </property> </bean>
修改为:
<bean id="connectionFactory" class="org.apache.activemq.pool.PooledConnectionFactory"> <property name="connectionFactory"> <bean class="org.apache.activemq.ActiveMQConnectionFactory"> <property name="brokerURL" value="tcp://huzq-linux:61616" /> </bean> </property> </bean>
相关推荐
方新德 2020-04-20
胡献根 2020-02-23
胡献根 2020-02-13
WindyQCF 2014-05-12
lnsoftware 2014-05-11
nickfover 2017-07-14
billmingchen 2017-08-21
胡献根 2019-10-21
Jolestar 2018-04-12
activemq 2017-11-05
Jolestar 2016-06-02
liuweiITlove 2016-05-26
Jolestar 2015-04-11
zkpy0 2013-03-15
activemq 2012-11-21
taikewu 2012-11-21
落羽成舟 2019-07-05