NutzCN Logo
问答 ioc 被 gc 回收~~~~~~
发布于 2517天前 作者 xzh0315 1943 次浏览 复制 上一个帖子 下一个帖子
标签:

public class IocBuilder implements Serializable{
private static final long serialVersionUID = -427436296422353911L;
protected static Ioc ioc;

public static Ioc ioc(String path) {
    if (ioc == null)
       ioc = new NutIoc(new ComboIocLoader(new AnnotationIocLoader("org.cimiss2.dwp.core"), new JsonLoader(path+"ioc/")));
    return ioc;//config/ioc/dao.json
}

}
获取的时候是这样:
static Ioc ioc;
private SurfREGEtl surfREGEtl;
public void prepare() {
ioc = IocBuilder.ioc(path);
surfREGEtl =ioc.get(SurfREGEtl.class);
}
还是被gc了 不知道为什么???求解~

11 回复

为啥要new ioc容器呢? 非nutz mvc环境?

是的 ,不是mvc

桌面应用?

就是一段数据入库代码,不是很复杂

2018-01-30 12:52:18 20664502 [Finalizer] INFO org.nutz.ioc.impl.NutIoc - org.nutz.ioc.impl.NutIoc@2065781579 is deposed. startup date [18-01-30 07:07:54.238]
2018-01-30 12:52:18 20664503 [Finalizer] ERROR org.nutz.ioc.impl.NutIoc - Ioc depose tigger by GC!!!
Common Reason for that is YOUR code call 'new NutIoc(...)', and then get some beans(most is Dao) from it and abandon it!!!
If using nutz.mvc, call Mvcs.ctx().getDefaultIoc() to get ioc container.
Not nutz.mvc? use like this: public static Ioc ioc;

7点生成,12点才回收,回收之前发生过什么呢?重新生成过ioc容器?老的被新的替换了?

IocBuilder 里面是static 而且做了if (ioc == null)判断才new ,如果有老的 不会new新的吧

多加些日志吧

[INFO ] 2018-01-30 07:07:54,200(0) --> [Thread-15-REGBolt-SURF_PQC_A.0001.0028.R001_000] org.nutz.ioc.loader.annotation.AnnotationIocLoader.(AnnotationIocLoader.java:56): Found 5 cla
sses in 1 base-packages!
beans = ["precipitationObservationDataRegEtl", "dayValueEtl", "surfBABJEtl", "surfREGEtl", "dayLightEtl"] [INFO ] 2018-01-30 07:07:54,200(0) --> [Thread-13-REGBolt-SURF_PQC_A.0001.0028.R001_001] org.nutz.ioc.loader.annotation.AnnotationIocLoader.(AnnotationIocLoader.java:56): Found 5 cla
sses in 1 base-packages!
beans = ["precipitationObservationDataRegEtl", "dayValueEtl", "surfBABJEtl", "surfREGEtl", "dayLightEtl"] [INFO ] 2018-01-30 07:07:54,200(0) --> [Thread-17-REGBolt-SURF_PQC_A.0001.0028.R001_001] org.nutz.ioc.loader.annotation.AnnotationIocLoader.(AnnotationIocLoader.java:56): Found 5 cla
sses in 1 base-packages!
beans = ["precipitationObservationDataRegEtl", "dayValueEtl", "surfBABJEtl", "surfREGEtl", "dayLightEtl"] [INFO ] 2018-01-30 07:07:54,200(0) --> [Thread-5-REGBolt-SURF_PQC_A.0001.0028.R001_001] org.nutz.ioc.loader.annotation.AnnotationIocLoader.(AnnotationIocLoader.java:56): Found 5 clas
ses in 1 base-packages!
beans = ["precipitationObservationDataRegEtl", "dayValueEtl", "surfBABJEtl", "surfREGEtl", "dayLightEtl"] [INFO ] 2018-01-30 07:07:54,261(61) --> [Thread-17-REGBolt-SURF_PQC_A.0001.0028.R001_001] org.nutz.ioc.impl.NutIoc.(NutIoc.java:98): NutIoc init begin ...
[INFO ] 2018-01-30 07:07:54,261(61) --> [Thread-5-REGBolt-SURF_PQC_A.0001.0028.R001_001] org.nutz.ioc.impl.NutIoc.(NutIoc.java:98): NutIoc init begin ...
[INFO ] 2018-01-30 07:07:54,261(61) --> [Thread-15-REGBolt-SURF_PQC_A.0001.0028.R001_000] org.nutz.ioc.impl.NutIoc.(NutIoc.java:98): NutIoc init begin ...
[INFO ] 2018-01-30 07:07:54,261(61) --> [Thread-13-REGBolt-SURF_PQC_A.0001.0028.R001_001] org.nutz.ioc.impl.NutIoc.(NutIoc.java:98): NutIoc init begin ...
[INFO ] 2018-01-30 07:07:54,264(64) --> [Thread-15-REGBolt-SURF_PQC_A.0001.0028.R001_000] org.nutz.ioc.impl.NutIoc.(NutIoc.java:121): ... NutIoc init complete
[INFO ] 2018-01-30 07:07:54,264(64) --> [Thread-5-REGBolt-SURF_PQC_A.0001.0028.R001_001] org.nutz.ioc.impl.NutIoc.(NutIoc.java:121): ... NutIoc init complete
[INFO ] 2018-01-30 07:07:54,263(63) --> [Thread-17-REGBolt-SURF_PQC_A.0001.0028.R001_001] org.nutz.ioc.impl.NutIoc.(NutIoc.java:121): ... NutIoc init complete
[INFO ] 2018-01-30 07:07:54,265(65) --> [Thread-13-REGBolt-SURF_PQC_A.0001.0028.R001_001] org.nutz.ioc.impl.NutIoc.(NutIoc.java:121): ... NutIoc init complete
[INFO ] 2018-01-30 07:07:54,663(463) --> [Thread-13-REGBolt-SURF_PQC_A.0001.0028.R001_001] org.nutz.dao.jdbc.Jdbcs.getExpert(Jdbcs.java:103): Get Connection from DataSource for JdbcExpert,
if you lock at here, check your database server and configure
[INFO ] 2018-01-30 07:07:54,663(463) --> [Thread-15-REGBolt-SURF_PQC_A.0001.0028.R001_000] org.nutz.dao.jdbc.Jdbcs.getExpert(Jdbcs.java:103): Get Connection from DataSource for JdbcExpert,
if you lock at here, check your database server and configure
[INFO ] 2018-01-30 07:07:54,663(463) --> [Thread-5-REGBolt-SURF_PQC_A.0001.0028.R001_001] org.nutz.dao.jdbc.Jdbcs.getExpert(Jdbcs.java:103): Get Connection from DataSource for JdbcExpert,
if you lock at here, check your database server and configure
[INFO ] 2018-01-30 07:07:54,663(463) --> [Thread-17-REGBolt-SURF_PQC_A.0001.0028.R001_001] org.nutz.dao.jdbc.Jdbcs.getExpert(Jdbcs.java:103): Get Connection from DataSource for JdbcExpert,
if you lock at here, check your database server and configure
[INFO ] 2018-01-30 07:07:54,973(773) --> [Thread-13-REGBolt-SURF_PQC_A.0001.0028.R001_001] org.nutz.dao.jdbc.Jdbcs.getExpert(Jdbcs.java:103): Get Connection from DataSource for JdbcExpert,
if you lock at here, check your database server and configure
[INFO ] 2018-01-30 07:07:54,974(774) --> [Thread-15-REGBolt-SURF_PQC_A.0001.0028.R001_000] org.nutz.dao.jdbc.Jdbcs.getExpert(Jdbcs.java:103): Get Connection from DataSource for JdbcExpert,
if you lock at here, check your database server and configure
[INFO ] 2018-01-30 07:07:54,975(775) --> [Thread-17-REGBolt-SURF_PQC_A.0001.0028.R001_001] org.nutz.dao.jdbc.Jdbcs.getExpert(Jdbcs.java:103): Get Connection from DataSource for JdbcExpert,
if you lock at here, check your database server and configure
[INFO ] 2018-01-30 07:07:54,975(775) --> [Thread-5-REGBolt-SURF_PQC_A.0001.0028.R001_001] org.nutz.dao.jdbc.Jdbcs.getExpert(Jdbcs.java:103): Get Connection from DataSource for JdbcExpert,
if you lock at here, check your database server and configure
[ERROR] 2018-01-30 10:40:50,023(12775823) --> [Finalizer] org.nutz.ioc.impl.NutIoc.finalize(NutIoc.java:336): Ioc depose tigger by GC!!!
Common Reason for that is YOUR code call 'new NutIoc(...)', and then get some beans(most is Dao) from it and abandon it!!!
If using nutz.mvc, call Mvcs.ctx().getDefaultIoc() to get ioc container.
Not nutz.mvc? use like this: public static Ioc ioc;
[INFO ] 2018-01-30 10:40:50,024(12775824) --> [Finalizer] org.nutz.ioc.impl.NutIoc.depose(NutIoc.java:261): org.nutz.ioc.impl.NutIoc@2065781579 is closing. startup date [18-01-30 07:07:54.
264] [INFO ] 2018-01-30 10:40:50,026(12775826) --> [Finalizer] org.nutz.ioc.impl.NutIoc.depose(NutIoc.java:274): org.nutz.ioc.impl.NutIoc@2065781579 is deposed. startup date [18-01-30 07:07:54.
264] [ERROR] 2018-01-30 10:40:50,026(12775826) --> [Finalizer] org.nutz.ioc.impl.NutIoc.finalize(NutIoc.java:336): Ioc depose tigger by GC!!!
Common Reason for that is YOUR code call 'new NutIoc(...)', and then get some beans(most is Dao) from it and abandon it!!!
If using nutz.mvc, call Mvcs.ctx().getDefaultIoc() to get ioc container.
Not nutz.mvc? use like this: public static Ioc ioc;
[INFO ] 2018-01-30 10:40:50,027(12775827) --> [Finalizer] org.nutz.ioc.impl.NutIoc.depose(NutIoc.java:261): org.nutz.ioc.impl.NutIoc@2057711407 is closing. startup date [18-01-30 07:07:54.
262] [INFO ] 2018-01-30 10:40:50,031(12775831) --> [Finalizer] org.nutz.ioc.impl.NutIoc.depose(NutIoc.java:274): org.nutz.ioc.impl.NutIoc@2057711407 is deposed. startup date [18-01-30 07:07:54.
262] [ERROR] 2018-01-30 10:40:50,031(12775831) --> [Finalizer] org.nutz.ioc.impl.NutIoc.finalize(NutIoc.java:336): Ioc depose tigger by GC!!!
Common Reason for that is YOUR code call 'new NutIoc(...)', and then get some beans(most is Dao) from it and abandon it!!!
If using nutz.mvc, call Mvcs.ctx().getDefaultIoc() to get ioc container.
Not nutz.mvc? use like this: public static Ioc ioc;
[INFO ] 2018-01-30 10:40:50,032(12775832) --> [Finalizer] org.nutz.ioc.impl.NutIoc.depose(NutIoc.java:261): org.nutz.ioc.impl.NutIoc@2124776006 is closing. startup date [18-01-30 07:07:54.
264] [INFO ] 2018-01-30 10:40:50,034(12775834) --> [Finalizer] org.nutz.ioc.impl.NutIoc.depose(NutIoc.java:274): org.nutz.ioc.impl.NutIoc@2124776006 is deposed. startup date [18-01-30 07:07:54.
264]

用 插入日志 按钮啊

[INFO ] 2018-01-30 07:07:54,264(64) --> [Thread-15-REGBolt-SURF_PQC_A.0001.0028.R001_000] org.nutz.ioc.impl.NutIoc.(NutIoc.java:121): ... NutIoc init complete
[INFO ] 2018-01-30 07:07:54,264(64) --> [Thread-5-REGBolt-SURF_PQC_A.0001.0028.R001_001] org.nutz.ioc.impl.NutIoc.(NutIoc.java:121): ... NutIoc init complete

每个线程建一个ioc容器的节奏? 忘记加锁了吧

添加回复
请先登陆
回到顶部