Increasing performance of java.net.URLConnection

While working on the program for Homework 3, a student in this class discovered that URLConnection will attempt to keep an HTTP connection active with a website just in case you end up making multiple calls to that site. In the context of our Twitter homework example, depending on how you make the connection to Twitter, the JDK may try to keep the connection alive and therefore increase performance as it doesn't have to tear down and then immediately set-up that connection between calls. However, if you encounter a 502 or other error, in order to keep the connection alive, you need to read the entire error response off the buffer rather than just ignore it. If you fail to read the full error response, the connection is broken and you get slower performance. If you are interested, more details can be found here:

http://docs.oracle.com/javase/1.5.0/docs/guide/net/http-keepalive.html

© University of Colorado, Boulder 2011