java - Is RabbitMQ's AMQP.BasicProperties.Builder thread-safe? -
title pretty self-explanatory.
is amqp.basicproperties.builder
thread-safe? citations/sources?
i can't find indicates either way...
no, amqp.basicproperties.builder not thread-safe. tested using following class:
package com.anarsoft.agent; import java.util.concurrent.atomic.atomicinteger; import com.rabbitmq.client.amqp; public class testrabbitmq extends thread { static final amqp.basicproperties.builder builder = new amqp.basicproperties.builder(); static final atomicinteger threadcount = new atomicinteger(); public void run() { builder.clusterid("444").build(); threadcount.decrementandget(); } public static void main(string[] args) throws exception { for( int = 0 ; < 8 ; i++) { testrabbitmq testnumberformat = new testrabbitmq(); threadcount.addandget(1); testnumberformat.start(); } while(threadcount.get() > 0) { thread.sleep(1000); } } }
http://vmlens.com shows me fields accessed without synchronization. trace generated http://vmlens.com:
com/rabbitmq/client/amqp$basicproperties$builder.clusterid@28470003 (8,8) thread-0 (9) thread-1 (10) com.rabbitmq.client.amqp$basicproperties$builder.clusterid com.rabbitmq.client.amqp$basicproperties$builder.clusterid com.anarsoft.agent.testrabbitmq.run thread-2 (11) com.rabbitmq.client.amqp$basicproperties$builder.clusterid com.rabbitmq.client.amqp$basicproperties$builder.clusterid com.anarsoft.agent.testrabbitmq.run thread-3 (12) com.rabbitmq.client.amqp$basicproperties$builder.clusterid com.rabbitmq.client.amqp$basicproperties$builder.clusterid com.anarsoft.agent.testrabbitmq.run thread-4 (13) com.rabbitmq.client.amqp$basicproperties$builder.clusterid com.rabbitmq.client.amqp$basicproperties$builder.clusterid com.anarsoft.agent.testrabbitmq.run thread-5 (14) com.rabbitmq.client.amqp$basicproperties$builder.clusterid com.rabbitmq.client.amqp$basicproperties$builder.clusterid com.anarsoft.agent.testrabbitmq.run thread-6 (15) com.rabbitmq.client.amqp$basicproperties$builder.clusterid com.rabbitmq.client.amqp$basicproperties$builder.clusterid com.anarsoft.agent.testrabbitmq.run thread-7 (16) com.rabbitmq.client.amqp$basicproperties$builder.clusterid com.rabbitmq.client.amqp$basicproperties$builder.clusterid com.anarsoft.agent.testrabbitmq.run
you can see source not threadsafe: http://grepcode.com/file/repo1.maven.org/maven2/com.rabbitmq/amqp-client/2.6.1/com/rabbitmq/client/amqp.java#amqp.basicproperties.builder
public builder clusterid(string clusterid) { this.clusterid = clusterid; return this; }
Comments
Post a Comment