如果我停止OSGi框架,则OSGi蓝图组件不会被破坏(不调用销毁方法)。为什么会这样,我如何销毁它们。我有自己的OSGi启动器实现。我正在使用关闭钩子,然后停止OSGi框架:
Runtime.getRuntime().addShutdownHook(new Thread() {
@Override
public void run() {
Launcher.logService.log(LogService.LOG_WARNING, "HANDLE SHUTDOWN");
if(Launcher.framework != null) {
try {
Launcher.framework.stop();
} catch (BundleException e) {
Launcher.logService.log(LogService.LOG_ERROR, "Shutdown" + ((Launcher.framework != null) ? " of " + Launcher.framework.getSymbolicName() + " " : " ") + "failed!", e);
System.exit(-1);
}
}
}
});
答案 0 :(得分:0)
我们应该等待框架停止运行。
Runtime.getRuntime().addShutdownHook(new Thread() {
@Override
public void run() {
Launcher.logService.log(LogService.LOG_WARNING, "HANDLE SHUTDOWN");
if(Launcher.framework != null) {
try {
Launcher.framework.stop();
Launcher.framework.waitForStop(0); // !!!
} catch (BundleException e) {
Launcher.logService.log(LogService.LOG_ERROR, "Shutdown" + ((Launcher.framework != null) ? " of " + Launcher.framework.getSymbolicName() + " " : " ") + "failed!", e);
System.exit(-1);
}
}
}
});