2014-03-27 31 views
1

我可以在我的遗留应用程序中看到下面的代码。一旦我运行main方法,我发现这个线程永远运行。 但是在调试时,为什么线程永远运行?这个线程如何在Spring中继续运行?

import org.apache.commons.logging.Log; 
import org.apache.commons.logging.LogFactory; 
import org.springframework.context.support.ClassPathXmlApplicationContext; 

public class MyClass { 

    public static void main(String[] args) { 
     ClassPathXmlApplicationContext applicationContext = new ClassPathXmlApplicationContext(ResourcesFactoryApplicationContext.getInstance()); 
     applicationContext.registerShutdownHook(); 
     applicationContext.setAllowBeanDefinitionOverriding(false); 
     applicationContext.setConfigLocation("configFileName"); 
     applicationContext.refresh(); 
    } 

} 
+2

有人谁知道更多关于Spring比我也许能回答这个问题的时候了,所以这可能是一个愚蠢的请求,但是你可以张贴在调试器显示正在运行的线程的堆栈跟踪? –

+1

您确定所讨论的线程是使用'main()'的线程,而不是其中一个Spring bean启动的其他线程吗? – axtavt

+0

如果不是deamon线程,每个线程将永远运行。 – robermann

回答

0

进程继续运行的原因是非守护线程仍在运行。从你的代码中主线程必须终止,所以应用程序必须已经在其中一个bean中启动了其他线程。