多线程访问网页+高并发测试网站

多线程访问网页+高并发测试网页

仅供学习,请勿用于非法用途。


线程类如下


import java.io.IOException;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;

public class TestThread extends Thread{
    
    private String httpurl;
    
    public TestThread(String httpurl){
        this.httpurl = httpurl;
    }
    
    public void run() {
        HttpURLConnection connection = null;
        InputStream urlStream = null;
        URL url = null;
          try {
            url = new URL(httpurl);

            connection = (HttpURLConnection)url.openConnection();
            connection.connect();
            urlStream = connection.getInputStream();
            Thread.sleep(10L); } catch (InterruptedException e) {
          }
          catch (MalformedURLException e)
          {
            e.printStackTrace();
          }
          catch (IOException e) {
            e.printStackTrace();
          }
      }
}


启动类如下


public class Test {
	
	public static void main(String[] args) {
		while (true) {
			//仅供学习请勿用于非法用途
			startThead();
		}
	}
	
	public static int threadCount = 55;   //线程数量
	private static boolean isRunGrabThread = true;     //抓取线程是否执行完毕
	static int  num = 1; //动态参数
	
	public static void startThead(){
		Thread[] grabThreads= new Thread[threadCount];	
		try{		  
			//开启-数据抓取子线程
		  	for(int i=0;i


你可能感兴趣的:(多线程访问网页+高并发测试网站)