[rabbitmq-discuss] Java client lib: up to 5 threads created in client when server publishes new message

Simon MacMullen simon at rabbitmq.com
Mon Sep 3 17:40:58 BST 2012


On 02/09/12 14:06, sharonbn wrote:
> Hello,

Hi.

> I created a simple client in Java, which consumes messages from a queue in a
> loop.
> what I see in the debugger, is that whenever I publish a new message into
> queue "q0"
> a new thread is opened in the client.  until 5 threads are open and running.
> (this is besides the single thread named "AMQP Connection")
> the threads begin when the messages are published, not when they are
> consumed...
>
> is this expected behavior?

Yes. This is the thread pool for consumer callbacks to get executed in.

> can this be changed?

Yes, invoke ConnectionFactory.newConnection(ExecutorService, Address[]) 
with a different ExecutorService.

Cheers, Simon

> here is the stack trace, the client code is below.
>
> Test at localhost:62105	
> 	Thread [main] (Suspended (breakpoint at line 19 in Test))	
> 		Test.main(String...) line: 19	
> 	Thread [AMQP Connection 204.236.192.179:1883] (Running)	
> 	Thread [pool-1-thread-1] (Running)	
> 	Thread [pool-1-thread-2] (Running)	
> 	Thread [pool-1-thread-3] (Running)	
> 	Thread [pool-1-thread-4] (Running)	
> 	Thread [pool-1-thread-5] (Running)	
>
> thanks,
> Sharon.
>
>
> import com.rabbitmq.client.*;
>
> public class Test
> {
> 	static Connection connection;
> 	static Channel channel;
> 	static QueueingConsumer consumer;
>
> 	public static void main (String... args) throws Exception
> 	{
> 		ConnectionFactory factory = new ConnectionFactory();
> 		factory.setHost(Constants.server);
> 		factory.setPort(Constants.port);
> 		connection = factory.newConnection();
> 		channel = connection.createChannel();
> 		consumer = new QueueingConsumer(channel);
> 		channel.basicConsume("q0", true, consumer);
>
> 		for (int i = 0 ; i<  10 ; i++) {
> 			QueueingConsumer.Delivery d = consumer.nextDelivery();
> 			System.out.println(" got: " + new String(d.getBody()));
> 			try { Thread.sleep(1000); } catch (InterruptedException e) {}
> 		}
> 	}
> }
>
>
>
>
> --
> View this message in context: http://rabbitmq.1065348.n5.nabble.com/Java-client-lib-up-to-5-threads-created-in-client-when-server-publishes-new-message-tp21751.html
> Sent from the RabbitMQ mailing list archive at Nabble.com.
> _______________________________________________
> rabbitmq-discuss mailing list
> rabbitmq-discuss at lists.rabbitmq.com
> https://lists.rabbitmq.com/cgi-bin/mailman/listinfo/rabbitmq-discuss


-- 
Simon MacMullen
RabbitMQ, VMware


More information about the rabbitmq-discuss mailing list