java多线程采集+线程同步-【多线程数据采集之四】
前些日子讲解了java数据抓取, 今天就讲解最核心的。 java多线程数据抓取。
java多线程采集+数据同步+线程同步【多线程数据采集之四】
主要讲解多线程抓取,多线程同步,多线程启动,控制等操作。
转载请用链接注明: 来源博客http://blog.csdn.net/yjflinchong
文章栏目列表:http://blog.csdn.net/column/details/threadgrab.html
先讲解第一步,线程类。 核心数据抓取线程。
这个例子主要讲解的是 对设定的天数的数据抓取。 从当前日期往后推。
每个线程负责一天的数据任务抓取。
源代码如下:
1、线程类
package com.yjf.util;import java.io.BufferedInputStream;import java.io.FileInputStream;import java.io.InputStream;import java.util.ArrayList;import java.util.Date;import java.util.List;import java.util.Properties;import java.util.Timer;public class Main {private static boolean isRunGrabThread = true; //抓取线程是否执行完毕public static int threadCount = 3; //线程数量public static int daycount = 30; //查询总天数public static int thisdaycount = 0;public static int isadsl = 0;public static int adslcount = 1;public static void main(String[] args) {try {startThead();//启动抓取数据主线程} catch (Exception e) {e.printStackTrace();}}public static void startThead(){Thread[] grabThreads= new Thread[threadCount];try{ //开启-数据抓取子线程 for(int i=0;i<grabThreads.length;i++){ Thread searchThread=new GetWebThread(); grabThreads[i] = searchThread; grabThreads[i].setDaemon(true); grabThreads[i].start(); } isRunGrabThread = true; //监控子线程,全部完成程序退出 WhileLoop: while(true){ //拨号策略控制 //reconnectControl(); //判断子线程是否运行完成 for(int i=0;i<threadCount;i++){ if(grabThreads[i].isAlive()){ Thread.sleep(3*1000); continue WhileLoop; } } //所有抓取线程执行完毕 isRunGrabThread = false; //子线程执行完毕则退出 break; }}catch (Exception e) {System.out.println("main主线程--系统异常!");}}}【多线程数据采集之四】java多线程采集+数据同步+线程同步- 7楼qq54592366421分钟前
- 群猪 老夫来也
- 6楼wsmwqp昨天 08:57
- 顶起来
- 5楼yjflinchong昨天 17:03
- 好文章,支持下
- 4楼yjflinchong昨天 14:09
- 请支持原创。 转载请注明链接。
- 3楼EvilGreenArmy昨天 14:07
- 疯子哥 文笔犀利,言简意赅,实来脍炙人口的 千古佳作啊!
- Re: yjflinchong昨天 14:08
- 回复EvilGreenArmyn我草。。。 你太猛了吧
- 2楼aspire_1昨天 14:05
- 回去好好学习下
- 1楼yjflinchong昨天 14:01
- 好文章,得顶。