JavaAntiPatterns

Collection of bad coding practices

Using URLs in Collections

with one comment

java.net.URL objects used as Map keys or Set items can result in a big performance issue. Internal implementation of equals() and hashCode() methods of java.net.URL class performs domain name resolution, so the time of their execution relies on an internet connection speed. If a computer is off-line, the time is nearly equal to a connection timeout (tens of seconds).

The same problem arises every time when URLs equality checking or hash code computation is performed.

Do not use java.net.URL to keep URL values. Use java.net.URI objects or the simple Strings instead.

See also:

Advertisements

Written by Alex

November 22, 2007 at 12:25 pm

Posted in Collections

Tagged with , , , , , ,

One Response

Subscribe to comments with RSS.

  1. […] Using URLs in Collections […]


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: