mirror of
https://github.com/Athou/commafeed.git
synced 2026-03-21 21:37:29 +00:00
better refresh algorithm using queues instead of synchronous database call
This commit is contained in:
@@ -5,28 +5,20 @@ import java.io.InputStreamReader;
|
||||
import java.util.Arrays;
|
||||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
import javax.annotation.PreDestroy;
|
||||
import javax.ejb.ConcurrencyManagement;
|
||||
import javax.ejb.ConcurrencyManagementType;
|
||||
import javax.ejb.Singleton;
|
||||
import javax.ejb.Startup;
|
||||
import javax.enterprise.inject.Instance;
|
||||
import javax.inject.Inject;
|
||||
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.apache.commons.lang.mutable.MutableBoolean;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
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.FeedRefreshWorker;
|
||||
import com.commafeed.backend.feeds.FeedRefreshTaskGiver;
|
||||
import com.commafeed.backend.model.ApplicationSettings;
|
||||
import com.commafeed.backend.model.UserRole.Role;
|
||||
import com.commafeed.backend.services.ApplicationSettingsService;
|
||||
@@ -45,15 +37,6 @@ public class StartupBean {
|
||||
@Inject
|
||||
DatabaseUpdater databaseUpdater;
|
||||
|
||||
@Inject
|
||||
FeedDAO feedDAO;
|
||||
|
||||
@Inject
|
||||
FeedCategoryDAO feedCategoryDAO;
|
||||
|
||||
@Inject
|
||||
FeedSubscriptionDAO feedSubscriptionDAO;
|
||||
|
||||
@Inject
|
||||
UserDAO userDAO;
|
||||
|
||||
@@ -61,17 +44,14 @@ public class StartupBean {
|
||||
UserService userService;
|
||||
|
||||
@Inject
|
||||
ApplicationSettingsService applicationSettingsService;
|
||||
FeedRefreshTaskGiver taskGiver;
|
||||
|
||||
@Inject
|
||||
Instance<FeedRefreshWorker> workers;
|
||||
ApplicationSettingsService applicationSettingsService;
|
||||
|
||||
private long startupTime;
|
||||
private Map<String, String> supportedLanguages = Maps.newHashMap();
|
||||
|
||||
private ExecutorService executor;
|
||||
private MutableBoolean running = new MutableBoolean(true);
|
||||
|
||||
@PostConstruct
|
||||
private void init() {
|
||||
|
||||
@@ -84,23 +64,7 @@ public class StartupBean {
|
||||
applicationSettingsService.applyLogLevel();
|
||||
|
||||
initSupportedLanguages();
|
||||
|
||||
ApplicationSettings settings = applicationSettingsService.get();
|
||||
int threads = settings.getBackgroundThreads();
|
||||
log.info("Starting {} background threads", threads);
|
||||
|
||||
executor = Executors.newFixedThreadPool(Math.max(threads, 1));
|
||||
for (int i = 0; i < threads; i++) {
|
||||
final int threadId = i;
|
||||
executor.execute(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
FeedRefreshWorker worker = workers.get();
|
||||
worker.start(running, "Thread " + threadId);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
taskGiver.start();
|
||||
}
|
||||
|
||||
private void initSupportedLanguages() {
|
||||
@@ -145,17 +109,4 @@ public class StartupBean {
|
||||
public Map<String, String> getSupportedLanguages() {
|
||||
return supportedLanguages;
|
||||
}
|
||||
|
||||
@PreDestroy
|
||||
public void shutdown() {
|
||||
running.setValue(false);
|
||||
executor.shutdownNow();
|
||||
while (!executor.isTerminated()) {
|
||||
try {
|
||||
Thread.sleep(100);
|
||||
} catch (InterruptedException e) {
|
||||
log.error("interrupted while waiting for threads to finish.");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user