Reputation: 4235
I am using HttpsURLConnection in Java and through some sort of loop i am creating 10 connections which later on used by different threads inside my program.
HttpsURLConnection connection = null;
connection = (HttpsURLConnection) url.openConnection();
Wondering how can i know which connection is used by current thread. I Just need some unique identifier of the connection.
Some thing like,
System.out.println(connection);
But above System.out statement is printing pretty generic server name. Not the hash code of connection object.
Wondering how can i do that?
Upvotes: 0
Views: 258
Reputation: 112
Hashcode could be same for both. Remember Hashcode and equals contract in javadocs.
please try to avoid relying on hashcode. As its not a good practice and in general cases hashcode are different each time. But its not assured to be unique.
You can use something like connection management api.
Please refer to below link. May be it can help.
If you can share your code or whole picture i can help in better way.
http://www.baeldung.com/httpclient-connection-management
Upvotes: 0