Impacts of having unused JAR files in CLASSPATH

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-06 23:29:14

问题


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).


回答1:


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.




回答2:


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")




回答3:


Yes, it has an impact - because the JVM looks for necessary classes in the JARs of the CLASSPATH. It also makes sense to keep sealed JARs, to tell the JVM not to look for related classes in other JARs.

P.S.: javac is also a java program, for the record.



来源:https://stackoverflow.com/questions/10980483/impacts-of-having-unused-jar-files-in-classpath

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!