fix: issue #IGOE4 in gitee

This commit is contained in:
Wendal Chen 2017-12-07 22:48:17 +08:00
parent e343212f82
commit 1fcbbf3125
2 changed files with 38 additions and 15 deletions

View File

@ -120,6 +120,8 @@ public class AppContext implements LifeCycle {
if (object instanceof LifeCycle)
((LifeCycle) object).depose();
}
if (ioc != null)
ioc.depose();
}
public void startServers() throws Exception {

View File

@ -44,7 +44,7 @@ import org.nutz.mvc.annotation.IocBy;
* @author wendal
*
*/
public class NbApp {
public class NbApp extends Thread {
/**
* 日志属性要等日志适配器准备好了才能加载,这里不可以使用Logs.get();
@ -88,6 +88,8 @@ public class NbApp {
protected boolean prepared;
protected Object lock = new Object();
/**
* 创建一个NbApp,把调用本构造方法的类作为mainClass
*/
@ -147,10 +149,18 @@ public class NbApp {
return ctx;
}
public void run() {
try {
_run();
} catch (Throwable e) {
Logs.get().error("something happen", e);
}
}
/**
* 启动整个NbApp
*/
public void run() throws Exception {
public void _run() throws Exception {
Stopwatch sw = Stopwatch.begin();
// 各种预备操作
@ -163,24 +173,35 @@ public class NbApp {
}
// 依次启动
ctx.init();
ctx.startServers();
if (mainClass.getAnnotation(IocBean.class) != null)
ctx.getIoc().get(mainClass);
sw.stop();
log.infof("NB started : %sms", sw.du());
// 等待关闭
Lang.quiteSleep(Integer.MAX_VALUE);
try {
ctx.init();
ctx.startServers();
if (mainClass.getAnnotation(IocBean.class) != null)
ctx.getIoc().get(mainClass);
sw.stop();
log.infof("NB started : %sms", sw.du());
synchronized (lock) {
lock.wait();
}
}
catch (Throwable e) {
log.error("something happen!!", e);
}
// 收尾
ctx.stopServers();
ctx.depose();
}
public void shutdown() {
log.info("ok, shutting down ...");
synchronized (lock) {
lock.notify();
}
}
/**
* 执行预备操作
*/