我在Java中使用HttpsURLConnection並通過某種循環創建了10個連接,稍後由我的程序中的不同線程使用。如何獲得HttpsUrlConnection對象的唯一ID
HttpsURLConnection connection = null;
connection = (HttpsURLConnection) url.openConnection();
想知道如何知道當前線程使用哪個連接。我只需要一些連接的唯一標識符。
一些東西一樣,
System.out.println(connection);
但上面的System.out語句印刷非常通用的服務器名稱。不是連接對象的哈希碼。
想知道我該怎麼做?
也許'connection.hashCode()'? – TeWu
謝謝Tewu。這個Api方法有些過頭了。請在答案框中回覆。 – Ammad
或者['System.identityHashCode(connection)'](http://stackoverflow.com/questions/4930781/how-do-hashcode-and-identityhashcode-work-at-the-back-end) – zapl