我有三个模块: module-a,module-b和module-c。 Module-a和module-b在引导层中。我自己创建了module-c的层。 Module-c具有服务的JPMS实现,该接口在module-a中。
这是我在module-b中创建包含module-c的层的方式。
这是我在module-b中创建包含module-c的层的方式。
ModuleFinder finder = ModuleFinder.of(moduleCPath);
ModuleLayer parent = ModuleLayer.boot();
Configuration cf = parent.configuration().resolve(finder, ModuleFinder.of(), Set.of("module-c"));
ClassLoader scl = ClassLoader.getSystemClassLoader();
ModuleLayer layer = parent.defineModulesWithOneLoader(cf, scl);
然后在模块B中,我调用了模块C的服务。当服务执行完成后,我不再需要模块C和新创建的层。如何将其从JVM中删除并释放所有资源?只做layer = null;
就足够了吗?
module-c
的新ModuleLayer
无法工作吗? - Namanlayer
将不再使用。我想要做的是将这个layer
从内存中移除并释放所有资源。 - Pavel_K