简体   繁体   中英

Are java .class files needed after an application is running?

I had a hard time writing the title to this question, but here is my situation and what I am asking:

  • I have a Java project that I run "ant test" on to run the tests
  • The tests take about 10 minutes to run
  • Can I switch to a different Git branch in the middle of running these tests without consequences?
  • I want the tests to complete against the original code, and allow me to simply work on a different branch while that happens.

I guess the root of my question is: Are .class files needed after the application is loaded and running? Is the classes just stored in memory, and I don't need the files on the file system anymore? Or does it still access/read things on the filesystem?

Any insight or better understanding of what java needs for a running application is appreciated.

Classes are loaded on demand. The classloader won't attempt to load a class until that class has been referenced. Therefore, removing class files from the classpath in the middle of a run would almost certainly cause failures.

如果您在测试运行时没有编译从Git到同一位置的.java文件,那么无论IDE如何加载类,您都不会遇到.class文件的问题。

在标准(我的意思是sun / oracle)JVM中,一旦加载了类,它就会一直停留在内存中,直到jvm关闭,但由于类是按需加载的,所以它可能还没有加载。

如果所有文件都已加载到内存中,则不需要...但是如何确保所有类都已加载到内存中...所以你需要类路径中的类文件

Well I think you have to do a step backwards and rethink the solution.

You wrote, that you execute integration tests. And as a part of the test you are switching the sources, that are tested. If you do this, you will produce useless test data, because you can't be sure, what was really executed.

If you want to test two different vrsion / branches of you software, just enable two test runs and compare the results.

You can only be sure, that a *.class file is loaded, if you have used it. After löoading the class file, it stays in the memory of the JVM. Maybe it will be unloaded if it is unused for some time and the GEM-space getting low (but I don't think so).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM