Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Impacts of having unused JAR files in CLASSPATH

I've read so many Q&A here about tools available to find out unused JARs, such as:

  1. loosejar
  2. Classpath Helper

My question here is, are there any impacts (such as loading of classes into memory, performance, etc.) of having unused JARs in the classpath either at compile time or run time? Question applies to both running as a Standalone program and Web Server (Apache Tomcat), though I initially thought about only Standalone programs.

NOTE: I'm running JDK 6u32 (64-bit).

like image 406
Gnanam Avatar asked Jun 11 '12 12:06

Gnanam


2 Answers

Are there any impacts (such as loading of classes into memory, performance, etc.) of having unused JARs in the classpath either at compile time or run time?

There is going to be a small impact. When the class loader (or the compiler's equivalent) starts, it has to read the index of each JAR file to find out what classes are in each JAR. If you've got unnecessary JARs on the classpath, the classloader has more work to do, and will (at least temporarily) use more memory to cache the indexes.

This applies to all kinds of Java application.

The question that you didn't ask is whether the impact is significant. The answer is "generally no" ... but the more "useless stuff" you have on the classpath, the greater the impact is going to be.

like image 149
Stephen C Avatar answered Oct 09 '22 20:10

Stephen C


The main problem is not performance as the cost is relatively small and only on loading new classes. The main problem is maintainability. For example, when a library needs to be upgraded, you can waste alot of time testing the application still works ok with the new version only to find the library was not used. (Say you have a new library which needs a newer version of a library you are already "using")

like image 23
Peter Lawrey Avatar answered Oct 09 '22 19:10

Peter Lawrey