【发布时间】:2015-01-04 18:56:11
【问题描述】:
public class Tasker{
ConfigurableApplicationContext context ;
public void load(){
context = = loadSpringContext();
}
pulic void doSomething(){
//do something
}
public void close(){
context.close();
}
}
public class Caller extends Thread {
public void run(){
Tasker tasker = new Tasker();
try{
tasker.load();
tasker.doSomething();
}finally(){
tasket.close();
}
}
}
//sample driver code which is not in my control
Caller caller = new Caller()
caller.start();
caller.stop();
现在的问题是,如果 somone 调用杀死线程,我的 Spring 上下文永远不会关闭并且它是内存泄漏。我该如何防止它?
注意:我无法更改驱动程序代码。
【问题讨论】:
-
线程通常不会在 JVM 中“杀死”。 Thread.stop() 方法已弃用,不应使用。 “某人”是如何阻止
tasket.close()被调用的?
标签: java spring memory-leaks garbage-collection