Created
January 5, 2018 22:41
-
-
Save chermehdi/b3a43523c53a400ae7e78e40f9838fea to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.io.BufferedReader; | |
import java.io.InputStreamReader; | |
import java.net.HttpURLConnection; | |
import java.net.URL; | |
import java.util.concurrent.ExecutorService; | |
import java.util.concurrent.Executors; | |
/** | |
* @author Mehdi_Maick | |
**/ | |
public class Stress { | |
static final String BASE = ""; | |
public String sendRequest(String urlToRead) throws Exception { | |
StringBuilder result = new StringBuilder(); | |
URL url = new URL(urlToRead); | |
HttpURLConnection conn = (HttpURLConnection) url.openConnection(); | |
conn.setRequestMethod("GET"); | |
BufferedReader rd = new BufferedReader(new InputStreamReader(conn.getInputStream())); | |
String line; | |
while ((line = rd.readLine()) != null) { | |
result.append(line); | |
} | |
rd.close(); | |
System.out.println("thread " + Thread.currentThread().getName() + " done !"); | |
return result.toString(); | |
} | |
public static void main(String[] args) throws Exception { | |
ExecutorService executorService = Executors.newFixedThreadPool(50); | |
for (int i = 0; i < 1000; i++) { | |
executorService.submit(() -> { | |
try { | |
new Stress().sendRequest(BASE); | |
} catch (Exception e) { | |
e.printStackTrace(); | |
} | |
}); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment