-
Bug
-
Resolution: Fixed
-
Major
-
2.3.1
When the webapplication is shut down during RSS aggregator updates, the Thread pool of FastRSSFeedFetcher is not shut down properly and prevents the application from being shut down properly.
To fix this, Namics created a method in the ModuleLifecycle to fix this.
private void shutdownRssFeedFetcher() { RSSFeedFetcher fetcher = Components.getComponent(RSSAggregator.class).getFetcher(); if (fetcher instanceof FastRSSFeedFetcher) { FastRSSFeedFetcher fastFetcher = (FastRSSFeedFetcher) fetcher; try { Field executorServiceField = FastRSSFeedFetcher.class.getDeclaredField("executorService"); executorServiceField.setAccessible(true); Object executorServiceObject = executorServiceField.get(fastFetcher); if (executorServiceObject instanceof ExecutorService) { ExecutorService executorService = (ExecutorService) executorServiceObject; log.info("Shutting down feed fetcher executor service: " + executorService); List<Runnable> terminated = executorService.shutdownNow(); log.info("Cancelled {} Runnable instances.", terminated.size()); log.info("Terminating feed fetcher executor service: " + executorService); executorService.awaitTermination(5, TimeUnit.MINUTES); } } catch (Throwable e) { log.error("Could not shutdown RSS Feed Fetcher", e); } } }
Of course, it would be nice if the RSSFeedFetcher interface had a stop() method, and the RSSAggregator Module itself would stop it's fetcher.
To do this, I suggest a method like this:
public void shutdown() { List<Runnable> runnables = executor.shutdownNow(); log.info("Canceling {} RSS Update Tasks because of shutdown...", runnables.size()); try { if (executor.awaitTermination(5, TimeUnit.MINUTES)) { log.info("Termination successful."); } else { log.error("Termination timed out."); } } catch (InterruptedException e) { log.error("Termination error.", e); } }
Acceptance criteria