更新策略优化

This commit is contained in:
xiongxiaoyang 2020-01-13 14:26:55 +08:00
parent f046f5f69b
commit d898e412c7
2 changed files with 15 additions and 40 deletions

View File

@ -47,7 +47,7 @@ public class StartListener implements ServletContextListener {
while (true) { while (true) {
try { try {
log.info("crawlBooks执行中。。。。。。。。。。。。"); log.info("parseBooks执行中。。。。。。。。。。。。");
crawlSource.parse(); crawlSource.parse();
Thread.sleep(1000 * 60 * 5); Thread.sleep(1000 * 60 * 5);
@ -57,6 +57,20 @@ public class StartListener implements ServletContextListener {
} }
}).start(); }).start();
new Thread(() -> {
while (true) {
try {
log.info("updateBooks执行中。。。。。。。。。。。。");
crawlSource.update();
Thread.sleep(1000 * 60 * 10);
} catch (Exception e) {
log.error(e.getMessage(), e);
}
}
}).start();
} }
} }

View File

@ -1,39 +0,0 @@
package xyz.zinglizingli.books.core.schedule;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service;
import xyz.zinglizingli.books.core.crawl.BaseCrawlSource;
import xyz.zinglizingli.books.po.Book;
import xyz.zinglizingli.books.service.BookService;
import java.util.List;
/**
* 定时更新
*
* @author 11797
*/
@Service
@RequiredArgsConstructor
@Slf4j
public class UpdateBookSchedule {
private final BaseCrawlSource crawlSource;
/**
* 10分钟更新一次
*/
@Scheduled(fixedRate = 1000 * 60 * 10)
public void updateBook() {
log.info("UpdateBookSchedule。。。。。。。。。。。。");
crawlSource.update();
}
}