Skip to content

Commit

Permalink
multi-thread downloading
Browse files Browse the repository at this point in the history
  • Loading branch information
zfan01 committed Apr 11, 2015
1 parent 747fd68 commit c472f67
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 4 deletions.
15 changes: 13 additions & 2 deletions slave/Downloader.java → slave/DownloadThread.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,22 @@

import javax.net.ssl.HttpsURLConnection;

public class Downloader {
public class DownloadThread extends Thread{
private static final String USER_AGENT = "Mozilla/5.0";
private static final String parentURL = "http://www.zhihu.com/question/";
private int num;

public DownloadThread(int num){
this.num = num;
}

@Override
public void run(){
downloadByGet(num);
}

// HTTP GET request
public static void downloadByGet(int id){
private static void downloadByGet(int id){
PrintWriter out = null;

try {
Expand Down
33 changes: 31 additions & 2 deletions slave/Slave.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,36 @@
import java.util.*;
import java.awt.event.*;

public class Slave {
public static void main (String[] args) {
Downloader.downloadByGet(20727479);
HTMLParser.getQuestionsIDs(20727479);
//DownloadService service = new DownloadService();
//Thread t = new Thread(service);
//service.start();

TreeSet<Integer> idset = new TreeSet<Integer>();
idset.add(22266015);
idset.add(19566985);
idset.add(21826476);
idset.add(19561631);
idset.add(19566980);
idset.add(19566985);
idset.add(19801697);
idset.add(19810462);
idset.add(19902415);
idset.add(20014415);
idset.add(20120168);
idset.add(20187542);
idset.add(20200749);
idset.add(20261859);
idset.add(20376438);
idset.add(20727479);


while(!idset.isEmpty()){
Thread t = new DownloadThread(idset.pollFirst());
t.start();
}
System.err.println("Done");

}

Expand Down

0 comments on commit c472f67

Please sign in to comment.