/* In this test we create a ClassLoader, then use it to load and run another *jtregtest.Whentheothertesthascompleted,wewaitfortheClassLoader *tobegarbage-collected.Ifithasnotbeengc'dafterareasonable *amountoftime,thensomethingiskeepingareferencetotheClassLoader, *whichimpliesamemoryleak. * *Thistestcanbeappliedtoanyjtregtest,notjusttheMXBeantests.
*/
publicclass LeakTest { /* Ideally we would include MXBeanTest in the list of tests, since it *hasfairlycompletecoverage.However,theClassLoaderfailstobe *gc'dwhenwedothat,andIamunabletofigureoutwhy.Examining *aheapdumpshowsonlyweakreferencestotheClassLoader.Isuspect *somethingiswrongintheinternalsofthereflectionclasses,used *quiteheavilybyMXBeanTest.
*/ // private static Class<?>[] otherTests = {MXBeanTest.class};
// This class just makes it easier for us to spot our loader in heap dumps privatestaticclass ShadowClassLoader extends URLClassLoader {
ShadowClassLoader(URL[] urls, ClassLoader parent) { super(urls, parent);
}
}
publicstaticvoid main(String[] args) throws Exception {
System.out.println("Testing that no references are held to ClassLoaders " + "by caches in the MXBean infrastructure"); for (Class<?> testClass : otherTests)
test(testClass); if (failure != null) thrownew Exception("CLASSLOADER LEAK TEST FAILED: " + failure);
System.out.println("CLASSLOADER LEAK TEST PASSED"); if (args.length > 0) {
System.out.println("Waiting for input");
System.in.read();
}
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.