我有三个模块:模块-a、模块-b、模块-c。模块-a 和模块-b 在引导层。我自己创建的模块-c 层。Module-c 具有该服务的 JPMS 实现,该接口位于 module-a 中。
这是我在 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 调用服务。服务执行完成后,我不再需要 module-c 和新创建的层。如何将其从 JVM 中移除并释放所有资源?够了吗layer = null;
?