Note that there are some explanatory texts on larger screens.

plurals
  1. POThread with "While True" loop injected through spring stops after three or four days of execution
    text
    copied!<p>I'm developing a web site which is responsible for providing informations about an online radio. The webserver itself get informations from different sources (There is a database fed by an API, and also my streaming servers provide a few XML files that I use to extract several important informations on the fly).</p> <p>Well, my problem started when I decided to create audience alarms based on a watchdog thread, that reads the XML files from streaming servers, update an array with a fix length (a long array of 360 places, pre allocated, so nothing that big) and is accessed by an Action, which returns this array to be transformed in a graph by a java script routine. This watchdog thread, so, needs to be the same to every client accessing the web site, since the informations it provides need to be equal to everyone. Thus, I decided to use the spring framework to call the service that starts the Watchdog thread.</p> <p>It worked, every website sees the same information and the information was always updated... until the while true thread I created stopped, the last state of the array was kept, but the thread doesn't work anymore.</p> <p>The spring injection is defined as follows:</p> <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt; &lt;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"&gt; &lt;bean id="wowzaService" class="br.com.imusica.reports.services.radio.WowzaService"/&gt; &lt;/beans&gt; </code></pre> <p>The service (accessed through an action) is programmed as follows:</p> <pre><code>@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(); } } </code></pre> <p>This service is injected at the ApplicationContextInitializer class, as follows:</p> <pre><code>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"); } </code></pre> <p>The watchdog Thread is defined as a Component, and has a @Scope(BeanDefinition.SCOPE_SINGLETON) on it, extends thread, and so on. I'm wondering whether Spring is or not stopping this thread after some time. I assured that, when I update my data array, I don't append the information, but actually shift the values, discard the oldest one and insert the new value. So, a memory problem isn't happening.</p> <p>Thanks in advance for your help</p> <p>João Bruno</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload