| | |
| | | import java.util.Base64; |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | import java.util.concurrent.ExecutorService; |
| | | import java.util.concurrent.Executors; |
| | | |
| | | /** |
| | | * 新闻资讯 |
| | |
| | | |
| | | @Override |
| | | public void grabNews() { |
| | | addNews(1, PropertiesUtil.getProperty("IN_NEW_HTTP_API") + "stock-markets?key=" + PropertiesUtil.getProperty("IN_NEW_KEY") + "&type=6"); |
| | | // 创建固定大小的线程池,根据需求调整线程数量 |
| | | ExecutorService executor = Executors.newFixedThreadPool(2); |
| | | try { |
| | | // 提交美国新闻抓取任务 |
| | | executor.submit(() -> |
| | | addNews(1, PropertiesUtil.getProperty("US_HTTP_API") + "stock-markets?key=" + PropertiesUtil.getProperty("US_KEY") + "&type=1") |
| | | ); |
| | | // 提交墨西哥新闻抓取任务 |
| | | executor.submit(() -> |
| | | addNews(1, PropertiesUtil.getProperty("MX_HTTP_API") + "stock-markets?key=" + PropertiesUtil.getProperty("MX_KEY") + "&type=1") |
| | | ); |
| | | } finally { |
| | | // 关闭线程池 |
| | | executor.shutdown(); |
| | | } |
| | | |
| | | } |
| | | |
| | | private void addNews(Integer type, String url) { |