-
Notifications
You must be signed in to change notification settings - Fork 0
/
FetchURL.java
34 lines (30 loc) · 915 Bytes
/
FetchURL.java
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
import java.util.Vector;
import java.net.HttpURLConnection;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;
class FetchURL extends Thread{
private Vector<Long> responseTime;
private String LINK = "http://www.apple.com/index.html";
public FetchURL(Vector<Long> array) {
responseTime = array;
}
public void run() {
try {
URL url = new URL(LINK);
HttpURLConnection connection = (HttpURLConnection)url.openConnection();
connection.setRequestMethod("GET");
long start = System.currentTimeMillis();
connection.connect();
if (connection.getResponseCode() == 200) {
long end = System.currentTimeMillis();
responseTime.add(end-start);
}
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
}