爬虫+数据库写入启动器

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
package home;
 
import org.apache.log4j.Level;
import org.apache.log4j.Logger;
 
import java.util.Map;
import java.util.concurrent.CountDownLatch;
 
public class Main_ERRunner {
 
    public static void main(String[] args) {
        Logger.getLogger(cn.edu.hfut.dmic.webcollector.plugin.rocks.RocksDBManager.class).setLevel(Level.ERROR);
        Logger.getLogger(cn.edu.hfut.dmic.webcollector.crawler.Crawler.class).setLevel(Level.ERROR);
        CountDownLatch ERLatch = new CountDownLatch(1);
        CountDownLatch FDLatch = new CountDownLatch(Main_FinanceData.getStockNumber());
        CountDownLatch ERDBL = new CountDownLatch(1);
        CountDownLatch FDDBLatch = new CountDownLatch(Main_FinanceData.getStockNumber());
        Main_ExchangeRate ERCrawler = new Main_ExchangeRate(true, ERLatch);
        Main_FinanceData FDCrawler = new Main_FinanceData(true, FDLatch);
        try {
            ERCrawler.start(1);
            FDCrawler.start(1);
            FDLatch.await();
            ERLatch.await();
            new Thread(new Main_ExchangeRate2MySQL("USDCNY", ERDBL)).start();
            for (Map.Entry<String, String> entry : Main_FinanceData2MySQL.getStockName().entrySet()) {
                new Thread(new Main_FinanceData2MySQL(entry.getValue(),FDDBLatch)).start();
            }
            FDDBLatch.await();
            ERDBL.await();
        catch (Exception e) {
            e.printStackTrace();
        }
    }
}

留下评论