Commit 811c679b by zhiwei

修改定时器启动方式

parent 89981f4d
...@@ -142,20 +142,20 @@ public class WeiboHotSearchCrawler { ...@@ -142,20 +142,20 @@ public class WeiboHotSearchCrawler {
rank++; rank++;
} }
} catch (Exception e) { } catch (Exception e) {
logger.error("解析微博时时热搜时出现解析错误",e.fillInStackTrace()); logger.error("解析微博时时热搜时出现解析错误",e);
continue; continue;
} }
} }
return result; return result;
} catch (Exception e) { } catch (Exception e) {
logger.error("解析微博时时热搜时出现解析错误,数据不是json结构",e.fillInStackTrace()); logger.error("解析微博时时热搜时出现解析错误,数据不是json结构",e);
return Collections.emptyList(); return Collections.emptyList();
} }
}else{ }else{
logger.info("解析微博时时热搜时出现解析错误,页面结构有问题"); logger.info("解析微博时时热搜时出现解析错误,页面结构有问题");
} }
} catch (IOException e1) { } catch (IOException e1) {
logger.error("解析微博时时热搜时出现连接失败",e1.fillInStackTrace()); logger.error("解析微博时时热搜时出现连接失败",e1);
return Collections.emptyList(); return Collections.emptyList();
} }
return Collections.emptyList(); return Collections.emptyList();
......
...@@ -15,6 +15,10 @@ import com.zhiwei.searchhotcrawler.timer.WeiboTopicRun; ...@@ -15,6 +15,10 @@ import com.zhiwei.searchhotcrawler.timer.WeiboTopicRun;
import com.zhiwei.searchhotcrawler.timer.ZhihuHotSearchRun; import com.zhiwei.searchhotcrawler.timer.ZhihuHotSearchRun;
import com.zhiwei.tools.tools.ZhiWeiTools; import com.zhiwei.tools.tools.ZhiWeiTools;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
public class HotSearchRun { public class HotSearchRun {
...@@ -25,13 +29,29 @@ public class HotSearchRun { ...@@ -25,13 +29,29 @@ public class HotSearchRun {
new UpdateWechatUserRun().start(); new UpdateWechatUserRun().start();
ZhiWeiTools.sleep(10000); ZhiWeiTools.sleep(10000);
new CacheListener().startListen(); new CacheListener().startListen();
ScheduledExecutorService scheduledThreadPool = Executors.newScheduledThreadPool(6);
scheduledThreadPool.scheduleAtFixedRate(new WeiboHotSearchRun(), 0, 1, TimeUnit.MINUTES);
scheduledThreadPool.scheduleAtFixedRate(new BaiduHotSearchRun(), 0, 5, TimeUnit.MINUTES);
scheduledThreadPool.scheduleAtFixedRate(new SougoHotSearchRun(), 0, 5, TimeUnit.MINUTES);
scheduledThreadPool.scheduleAtFixedRate(new DouyinHotSearchRun(), 0, 10, TimeUnit.MINUTES);
scheduledThreadPool.scheduleAtFixedRate(new ZhihuHotSearchRun(), 0, 10, TimeUnit.MINUTES);
scheduledThreadPool.scheduleAtFixedRate(new WeiboTopicRun(), 0, 1, TimeUnit.DAYS);
//采集程序启动 //采集程序启动
new WeiboHotSearchRun().start(); // new WeiboHotSearchRun().start();
new BaiduHotSearchRun().start(); // new BaiduHotSearchRun().start();
new SougoHotSearchRun().start(); // new SougoHotSearchRun().start();
new DouyinHotSearchRun().start(); // new DouyinHotSearchRun().start();
new ZhihuHotSearchRun().start(); // new ZhihuHotSearchRun().start();
new WeiboTopicRun().start(); // new WeiboTopicRun().start();
//推送程序启动 //推送程序启动
new SendWeiboHotSearchRun().start(); new SendWeiboHotSearchRun().start();
new SendZhihuHotSearchRun().start(); new SendZhihuHotSearchRun().start();
......
...@@ -22,17 +22,17 @@ public class BaiduHotSearchRun extends Thread{ ...@@ -22,17 +22,17 @@ public class BaiduHotSearchRun extends Thread{
@Override @Override
public void run() { public void run() {
boolean f = true; // boolean f = true;
while(f) { // while(f) {
try { try {
getHotList(); getHotList();
TimeUnit.MINUTES.sleep(5); // TimeUnit.MINUTES.sleep(5);
} catch (Exception e) { } catch (Exception e) {
e.fillInStackTrace(); e.fillInStackTrace();
ZhiWeiTools.sleep(60*60*1000); // ZhiWeiTools.sleep(60*60*1000);
}
ZhiWeiTools.sleep(50);
} }
// ZhiWeiTools.sleep(50);
// }
} }
......
...@@ -21,17 +21,17 @@ public class DouyinHotSearchRun extends Thread{ ...@@ -21,17 +21,17 @@ public class DouyinHotSearchRun extends Thread{
@Override @Override
public void run() { public void run() {
boolean f = true; // boolean f = true;
while(f) { // while(f) {
try { try {
getHotList(); getHotList();
TimeUnit.MINUTES.sleep(10); // TimeUnit.MINUTES.sleep(10);
} catch (Exception e) { } catch (Exception e) {
e.fillInStackTrace(); e.fillInStackTrace();
ZhiWeiTools.sleep(60*60*1000); // ZhiWeiTools.sleep(60*60*1000);
}
ZhiWeiTools.sleep(50);
} }
// ZhiWeiTools.sleep(50);
// }
} }
/** /**
......
...@@ -20,17 +20,17 @@ public class SougoHotSearchRun extends Thread { ...@@ -20,17 +20,17 @@ public class SougoHotSearchRun extends Thread {
@Override @Override
public void run() { public void run() {
boolean f = true; // boolean f = true;
while(f) { // while(f) {
try { try {
getHotList(); getHotList();
TimeUnit.MINUTES.sleep(5); // TimeUnit.MINUTES.sleep(5);
} catch (Exception e) { } catch (Exception e) {
e.fillInStackTrace(); e.fillInStackTrace();
ZhiWeiTools.sleep(60*60*1000); // ZhiWeiTools.sleep(60*60*1000);
}
ZhiWeiTools.sleep(50);
} }
// ZhiWeiTools.sleep(50);
// }
} }
......
...@@ -21,17 +21,17 @@ public class WeiboHotSearchRun extends Thread{ ...@@ -21,17 +21,17 @@ public class WeiboHotSearchRun extends Thread{
@Override @Override
public void run() { public void run() {
boolean f = true; // boolean f = true;
while(f) { // while(f) {
try { try {
getHotList(); getHotList();
TimeUnit.MINUTES.sleep(1); // TimeUnit.MINUTES.sleep(1);
} catch (Exception e) { } catch (Exception e) {
e.fillInStackTrace(); e.fillInStackTrace();
ZhiWeiTools.sleep(60*1000); // ZhiWeiTools.sleep(60*1000);
}
ZhiWeiTools.sleep(50);
} }
// ZhiWeiTools.sleep(50);
// }
} }
......
...@@ -21,17 +21,17 @@ public class WeiboTopicRun extends Thread{ ...@@ -21,17 +21,17 @@ public class WeiboTopicRun extends Thread{
@Override @Override
public void run() { public void run() {
boolean f = true; // boolean f = true;
while(f) { // while(f) {
try { try {
getTopicList(); getTopicList();
TimeUnit.DAYS.sleep(1); // TimeUnit.DAYS.sleep(1);
} catch (Exception e) { } catch (Exception e) {
e.fillInStackTrace(); e.fillInStackTrace();
ZhiWeiTools.sleep(60*60*1000); // ZhiWeiTools.sleep(60*60*1000);
}
ZhiWeiTools.sleep(50);
} }
// ZhiWeiTools.sleep(50);
// }
} }
......
...@@ -20,17 +20,17 @@ public class ZhihuHotSearchRun extends Thread{ ...@@ -20,17 +20,17 @@ public class ZhihuHotSearchRun extends Thread{
@Override @Override
public void run() { public void run() {
boolean f = true; // boolean f = true;
while(f) { // while(f) {
try { try {
getHotList(); getHotList();
TimeUnit.MINUTES.sleep(10); // TimeUnit.MINUTES.sleep(10);
} catch (Exception e) { } catch (Exception e) {
e.fillInStackTrace(); e.fillInStackTrace();
ZhiWeiTools.sleep(60*60*1000); // ZhiWeiTools.sleep(60*60*1000);
}
ZhiWeiTools.sleep(50);
} }
// ZhiWeiTools.sleep(50);
// }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment