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();
Now the problem is if somone calls kills thread my Spring context is never closed and its a memeory leak.How can i prevent it?
Note: i cant change driver code.