Results 1 to 4 of 4

Thread: JMS client never terminates

  1. #1

    Default JMS client never terminates

    Hi all,

    I have a JMS client that uses Spring Integration and an <int-jms:outbound-gateway> to talk to an ActiveMQ server. My client code is able to send a request to the gateway proxy, and get a response back.

    But then something odd happens. The client does not end, it just seems to hang. In Eclipse I am able to pause the process and inspect the call stack, which looks like this:

    Code:
    Thread [ActiveMQ Transport: tcp://localhost/127.0.0.1:61616] (Suspended)	
    	SocketInputStream.socketRead0(FileDescriptor, byte[], int, int, int) line: not available [native method]	
    	SocketInputStream.read(byte[], int, int) line: 129	
    	TcpTransport$2(TcpBufferedInputStream).fill() line: 50	
    	TcpTransport$2.fill() line: 602	
    	TcpTransport$2(TcpBufferedInputStream).read() line: 58	
    	TcpTransport$2.read() line: 587	
    	DataInputStream.readInt() line: 370	
    	OpenWireFormat.unmarshal(DataInput) line: 275	
    	TcpTransport.readCommand() line: 229	
    	TcpTransport.doRun() line: 221	
    	TcpTransport.run() line: 204	
    	Thread.run() line: 662
    I'm guessing the gateway never stops listening for responses, even when there are no pending requests.

    Is this normal behaviour? Should I forcibly try to close the connection?

    Code:
    <bean id="connectionFactory" class="org.springframework.jms.connection.CachingConnectionFactory">
    	<property name="targetConnectionFactory">
    		<bean class="org.apache.activemq.ActiveMQConnectionFactory">
    			<property name="brokerURL" value="tcp://localhost:61616" />
    		</bean>
    	</property>
    	<property name="sessionCacheSize" value="10" />
    	<property name="clientId" value="activemqtestclient"/>
    </bean>

  2. #2
    Join Date
    Mar 2010
    Location
    Gtr Philadelphia, PA
    Posts
    2,029

    Default

    You are using a CachingConnectionFactory so the connection is, er, cached.

    That thread is an internal ActiveMQ thread for the connection.

    If your application only sends/receives one message, and you don't want the benefit of cached connections, then don't wrap the AMQ connection factory; just use it directly.

    If you want caching, then you can call resetConnection() on the factory before exiting.
    Gary P. Russell
    Spring Integration Team
    SpringSource, a division of VMware

  3. #3

    Default

    I didn't realize that caching connections meant that the connection would keep the process running after the main code was done. I imagined it was sort of like caching database connections.

    The client I use is a very simple testcase which only sends and receives one message. In the production environment the clients will be sending and receiving messages continuously. But I guess the question is relevant anyway, since the clients offer an "Exit" function so I have to handle the issue somehow. Thanks for the tip on resetConnection(), I'll give that a try.

  4. #4
    Join Date
    Mar 2010
    Location
    Gtr Philadelphia, PA
    Posts
    2,029

    Default

    Well, that's a function of the JMS provider; we don't have any control over what they do.

    ActiveMQ starts a transport thread for each open connection. If you want to know all the gory details... http://fusesource.com/wiki/display/P...ed+in+ActiveMQ
    Gary P. Russell
    Spring Integration Team
    SpringSource, a division of VMware

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •