Question

I have a bunch of threads, each creating an org.apache.qpid.client.AMQConnection and then a session.

public void run() {
    Connection connection = new AMQConnection("amqp://*******:*****@clientid/test?brokerlist='tcp://********:****?sasl_mechs='ANONYMOUS''");
    connection.start();

    Session ssn = connection.createSession(false,Session.AUTO_ACKNOWLEDGE);    
    System.out.println(ssn.toString());

    ssn.close();
    connection.close();
}

On some runs, I get the same Session.hashCode() in two different threads like so:

org.apache.qpid.client.AMQSession_0_10@420e44
org.apache.qpid.client.AMQSession_0_10@d76237
org.apache.qpid.client.AMQSession_0_10@d76237
org.apache.qpid.client.AMQSession_0_10@7148e9

Now I understand hashcode() is not guaranteed to be unique, how can I prove or disprove that createSession() returns the same session object on two separate threads?

Was it helpful?

Solution

Turned out to be more of a Java object equivalency question rather than anything to do with qpid or messaging.

Instead of printing hashcodes, I inserted the Session objects themselves into a Vector<Session> and compared them (==). Turns out they were all unique across all threads.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top