Java loading and unloading .java files dynamically, garbage collection?

前端 未结 1 1037
無奈伤痛
無奈伤痛 2020-12-28 09:40

I am in the process of creating a java application that will be running for long periods of time which requires updated functionality without shutting down. I\'ve decided to

相关标签:
1条回答
  • 2020-12-28 09:48

    You seem to be using the application's default classloader to load the compiled classes - that makes it impossible for the classes to be garbage collected.

    So you have to create a separate classloader for your freshly compiled classes. This is how app servers do it.

    However, even if you use a separate classloader for your compiled classes, it can be tricky to get those classes to be picked up by garbage collection, because the classloader and all the classes it loaded are not eligible for garbage collcetion as long as a single instance of any of those classes is referred to anywhere else (i.e. the rest of your application).

    This is known as a classloader leak and a common problem with appservers, causing redeployments to use ever more memory and eventually fail. Diagnosing and fixing a classloader leak can be very tricky; the article has all the details.

    0 讨论(0)
提交回复
热议问题