shutdown pool when application stops

This commit is contained in:
Athou
2013-05-24 12:28:48 +02:00
parent d148fa9df7
commit 8039915bcf
2 changed files with 16 additions and 0 deletions

View File

@@ -27,6 +27,7 @@ import com.commafeed.backend.dao.FeedCategoryDAO;
import com.commafeed.backend.dao.FeedDAO;
import com.commafeed.backend.dao.FeedSubscriptionDAO;
import com.commafeed.backend.dao.UserDAO;
import com.commafeed.backend.feeds.FeedRefreshUpdater;
import com.commafeed.backend.feeds.FeedRefreshWorker;
import com.commafeed.backend.model.ApplicationSettings;
import com.commafeed.backend.model.UserRole.Role;
@@ -61,6 +62,9 @@ public class StartupBean {
@Inject
ApplicationSettingsService applicationSettingsService;
@Inject
FeedRefreshUpdater feedRefreshUpdater;
@Inject
Instance<FeedRefreshWorker> workers;
@@ -145,6 +149,7 @@ public class StartupBean {
log.error("interrupted while waiting for threads to finish.");
}
}
feedRefreshUpdater.shutdown();
}
}

View File

@@ -78,6 +78,17 @@ public class FeedRefreshUpdater {
});
}
public void shutdown() {
pool.shutdownNow();
while (!pool.isTerminated()) {
try {
Thread.sleep(100);
} catch (InterruptedException e) {
log.error("interrupted while waiting for threads to finish.");
}
}
}
public void updateFeed(Feed feed, Collection<FeedEntry> entries) {
pool.execute(new Task(feed, entries));
}