Java 用“线程”;“虽然是真的”;通过spring注入的循环在执行三到四天后停止

Java 用“线程”;“虽然是真的”;通过spring注入的循环在执行三到四天后停止,java,multithreading,spring,scope,webserver,Java,Multithreading,Spring,Scope,Webserver,我正在开发一个网站,负责提供有关在线广播的信息。Web服务器本身从不同的来源获取信息(有一个由API提供的数据库,我的流式服务器也提供一些XML文件,我使用这些文件动态提取一些重要信息) 当我决定基于看门狗线程创建观众警报时,我的问题就开始了,看门狗线程从流式服务器读取XML文件,用固定长度更新数组(一个360个位置的长数组,预先分配,所以没有那么大),并通过一个操作访问,它返回这个数组,并通过java脚本例程在图形中进行转换。因此,这个看门狗线程需要对每个访问网站的客户机都是相同的,因为它提供

我正在开发一个网站,负责提供有关在线广播的信息。Web服务器本身从不同的来源获取信息(有一个由API提供的数据库,我的流式服务器也提供一些XML文件,我使用这些文件动态提取一些重要信息)

当我决定基于看门狗线程创建观众警报时,我的问题就开始了,看门狗线程从流式服务器读取XML文件,用固定长度更新数组(一个360个位置的长数组,预先分配,所以没有那么大),并通过一个操作访问,它返回这个数组,并通过java脚本例程在图形中进行转换。因此,这个看门狗线程需要对每个访问网站的客户机都是相同的,因为它提供的信息需要对每个人都是平等的。因此,我决定使用spring框架调用启动看门狗线程的服务

它的工作,每个网站看到相同的信息和信息总是更新。。。直到我创建的while true线程停止,数组的最后一个状态才被保留,但线程不再工作

弹簧喷射的定义如下:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns:sec="http://www.springframework.org/schema/security" xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:ehcache="http://www.springmodules.org/schema/ehcache"
    default-autowire="byName"
    xsi:schemaLocation="
        http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
        http://www.springmodules.org/schema/ehcache http://www.springmodules.org/schema/cache/springmodules-ehcache.xsd">

    <bean id="wowzaService" class="br.com.imusica.reports.services.radio.WowzaService"/>

</beans>
@Component
@Scope(BeanDefinition.SCOPE_PROTOTYPE)
public class WowzaService extends AbstractService {

    @Autowired
    private WatchDogThread watchdog;

    public void startWatchdog() {
        watchdog.start();
    }

    public WatchDogArray getWatchdogArray() {
        return watchdog.getWatchDogArray();
    }
}
public synchronized void contextInitialized(ServletContextEvent contextEvent) {
    WebApplicationContext wac = WebApplicationContextUtils.getRequiredWebApplicationContext(contextEvent.getServletContext());

    WowzaService ws = (WowzaService) wac.getBean("wowzaService");
    ws.startWatchdog();

    CacheManager manager = (CacheManager) wac.getBean("cacheManager");
    MBeanServer mBeanServer = ManagementFactory.getPlatformMBeanServer();
    ManagementService.registerMBeans(manager, mBeanServer, false, false, false, true);

    cleanUpService = (CleanUpService) wac.getBean("cleanUpService");
    ApplicationContextInitializer.applicationDiskRootPath = contextEvent.getServletContext().getRealPath("/");

    ComplexReportsControllerService complexReportsService =
        (ComplexReportsControllerService) wac.getBean("complexReportsControllerService");
    complexReportsService.cleanUpUnfinishedReports();
    cleanUpService.setRootPath(ApplicationContextInitializer.applicationDiskRootPath);
    cleanUpService.cleanUpAllSessions();
    // StdScheduler schedulerFactoryBean;

    ApplicationContextInitializer.reportsBasePath = (String) wac.getBean("reportsDataPath");

}
此服务在ApplicationContextInitializer类中注入,如下所示:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns:sec="http://www.springframework.org/schema/security" xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:ehcache="http://www.springmodules.org/schema/ehcache"
    default-autowire="byName"
    xsi:schemaLocation="
        http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
        http://www.springmodules.org/schema/ehcache http://www.springmodules.org/schema/cache/springmodules-ehcache.xsd">

    <bean id="wowzaService" class="br.com.imusica.reports.services.radio.WowzaService"/>

</beans>
@Component
@Scope(BeanDefinition.SCOPE_PROTOTYPE)
public class WowzaService extends AbstractService {

    @Autowired
    private WatchDogThread watchdog;

    public void startWatchdog() {
        watchdog.start();
    }

    public WatchDogArray getWatchdogArray() {
        return watchdog.getWatchDogArray();
    }
}
public synchronized void contextInitialized(ServletContextEvent contextEvent) {
    WebApplicationContext wac = WebApplicationContextUtils.getRequiredWebApplicationContext(contextEvent.getServletContext());

    WowzaService ws = (WowzaService) wac.getBean("wowzaService");
    ws.startWatchdog();

    CacheManager manager = (CacheManager) wac.getBean("cacheManager");
    MBeanServer mBeanServer = ManagementFactory.getPlatformMBeanServer();
    ManagementService.registerMBeans(manager, mBeanServer, false, false, false, true);

    cleanUpService = (CleanUpService) wac.getBean("cleanUpService");
    ApplicationContextInitializer.applicationDiskRootPath = contextEvent.getServletContext().getRealPath("/");

    ComplexReportsControllerService complexReportsService =
        (ComplexReportsControllerService) wac.getBean("complexReportsControllerService");
    complexReportsService.cleanUpUnfinishedReports();
    cleanUpService.setRootPath(ApplicationContextInitializer.applicationDiskRootPath);
    cleanUpService.cleanUpAllSessions();
    // StdScheduler schedulerFactoryBean;

    ApplicationContextInitializer.reportsBasePath = (String) wac.getBean("reportsDataPath");

}
看门狗线程被定义为一个组件,它上面有一个@Scope(BeanDefinition.Scope\u SINGLETON),扩展线程,等等。我想知道春天是否会在一段时间后停止这条线。我保证,当我更新数据数组时,我不会附加信息,而是实际移动值,丢弃最旧的值并插入新值。所以,内存问题没有发生

提前谢谢你的帮助


João Bruno

Spring无法停止您的线程,您的线程由于某种原因失败。

WatchDogThread.run方法中的异常处理是什么?您的线程很可能抛出异常。您可能需要考虑在<代码>中包装<代码>运行(<)/>代码>方法> {{} catch(可抛出)< /代码>或使用<代码>线程.StUnCukTutExpAutoStutsHelpor(…)< /C> > @ AlexanderPogrebnyak我发现了2个错误。两者都有以下内容:信息:非法访问:此web应用程序实例已停止。无法加载com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderFactoryImpl。最终的后续堆栈跟踪是由出于调试目的抛出的错误以及试图终止导致非法访问的线程引起的,并且没有功能性imp act。我的意思是,在描述与我的线程相关的错误之前没有任何内容(事实上,日志非常大,我试图找到错误的开始,但只是找到了与“此线程不再存在”相关的错误。)无论如何,如果我没有找到spring的解决方案,我将使我的线程保持静态(这是我刚刚想到的!)非常感谢您的回答。事实上,我们发现问题与未经处理的异常有关,当我们需要向流媒体服务器提供信息时,会发生这种情况。