I have read everywhere that JAXBContext.newInstance(SampleClass.class)
will load the SampleClass
and create a JAXBContext
object from it. For example, last answer here and there were blogs as well.
But when I do following then I do not see class getting loaded 10000 times. I verified this using a profiling tool that SampleClass
is not loading 10000 times.
for (int i = 0; i < 10000; i++) {
JAXBContext jaxbContext = JAXBContext.newInstance(TestData.class);
jaxbContext.hashCode();
jaxbContext.toString();
jaxbContext.getClass();
}
Is my understanding about JAXBContext.newInstance
wrong?
I know that if a class is loaded by JVM then it will not be loaded again but this is what I have read everywhere that using JAXBContext.newInstance()
will load the class each time.
EDIT: Here is more observation from jVisualVM, I invoked it ~10000 but only ~200-300 class loading happened, and then 174 classes were shown as unloaded.