Skip to content

Instantly share code, notes, and snippets.

@Ramasubramanian
Created October 3, 2011 15:54
Show Gist options
  • Save Ramasubramanian/1259434 to your computer and use it in GitHub Desktop.
Save Ramasubramanian/1259434 to your computer and use it in GitHub Desktop.
Lookup Table
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