Created
October 3, 2011 15:54
-
-
Save Ramasubramanian/1259434 to your computer and use it in GitHub Desktop.
Lookup Table
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private static InetAddress[] checkLookupTable(String host) { | |
synchronized (lookupTable) { | |
// If the host isn't in the lookupTable, add it in the | |
// lookuptable and return null. The caller should do | |
// the lookup. | |
if (lookupTable.containsKey(host) == false) { | |
lookupTable.put(host, null); | |
return null; | |
} | |
// If the host is in the lookupTable, it means that another | |
// thread is trying to look up the addresses of this host. | |
// This thread should wait. | |
while (lookupTable.containsKey(host)) { | |
try { | |
lookupTable.wait(); | |
} catch (InterruptedException e) { | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment