Originally posted by raghav mathur:
Here is a scenrio where you need to use the URL connection object on every thread acess . Now the best way to do this would be to reuse the connection objects from a pool of such objects.
Bad example. The JVM keeps HTTP connections alive by default:
JDK 1.5.0 Release Notes. It is a bad idea to "guess" about performance without knowing what the JVM is doing because you could end up making your application perform worse because your assumptions are wrong:
7.6.1 Object Pooling
. . .with the new generation of JVM implementations that include advanced memory management systems, object pooling small objects is often counterproductive. The overhead of managing the object pool is often greater than the small object penalty. Pooling can also increase a program's memory footprint. The need for many of these small objects can often be avoided altogether by having control over object mutability. Pooling small objects is not a recommended tactic when you're working with the new generation of JVMs.
http://java.sun.com/docs/books/performance/1st_edition/html/JPMutability.fm.html#11379 The first rule of optimization is "don't do it".
"Premature optimization is the root of all evil".
The second rule is benchmark,
test, then benchmark again. The
Java Platform Performance book above is an excellent resource for learning how.
[ August 29, 2006: Message edited by: Joe Ess ]