wait for threads to finish before starting new ones

This commit is contained in:
Athou
2013-07-10 10:56:42 +02:00
parent d293926624
commit dd05bcbcde

View File

@@ -77,8 +77,10 @@ public class DatabaseCleaner {
do { do {
List<FeedCount> fcs = feedDAO.findDuplicates(0, 10, 1); List<FeedCount> fcs = feedDAO.findDuplicates(0, 10, 1);
deleted = fcs.size(); deleted = fcs.size();
List<Thread> threads = Lists.newArrayList();
for (final FeedCount fc : fcs) { for (final FeedCount fc : fcs) {
new Thread() { Thread thread = new Thread() {
public void run() { public void run() {
Feed into = feedDAO.findById(fc.feeds.get(0).getId()); Feed into = feedDAO.findById(fc.feeds.get(0).getId());
List<Feed> feeds = Lists.newArrayList(); List<Feed> feeds = Lists.newArrayList();
@@ -87,7 +89,16 @@ public class DatabaseCleaner {
} }
mergeFeeds(into, feeds); mergeFeeds(into, feeds);
}; };
}.start(); };
thread.start();
threads.add(thread);
}
for (Thread thread : threads) {
try {
thread.join();
} catch (InterruptedException e) {
log.error(e.getMessage(), e);
}
} }
total += deleted; total += deleted;
log.info("merged {} feeds", total); log.info("merged {} feeds", total);