Cleaning up after an external Java library

I use in my application some external, that is, jar, library, which, unfortunately, does not clean up correctly after itself, i.e. the second time I create an object from this library, it does not work properly. I suspect this is because the library creates some threads that continue to work, but I'm not sure.

Is there a way to forcefully clear the clutter created by an external library?

+3
source share
1 answer

There may be reasons not related to threads. For example, static class initializers start only once when the class is loaded for the first time. So something like this may occur:

public class StupidSingleton {
  private static StupidSingleton instance;

  public StupidSingleton() {
    if (instance == null) {
      instance = this;
    } else {
      instance.foo(); // the implementation is irrelevant in this context
    }
  }
}

, :

  • . .
  • ClassLoader. .
  • . . , proprietary_fixed.jar .
+1

Source: https://habr.com/ru/post/1757203/


All Articles