TestHttp

测试多线程访问。

package com.asin;

import java.io.IOException;

import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.HttpClients;

public class TestHttp {

	public static void main(String[] args) throws Exception {

		final long t1 = System.currentTimeMillis();

		for (int j = 0; j < 20; j++) {

			for (int i = 0; i < 2000; i++) {
				new Thread(new th()).start();
			}

			Thread.sleep(30000);
		}
		final long t2 = System.currentTimeMillis();
		System.out.println(t2 - t1);
	}
}

class th implements Runnable {

	@Override
	public void run() {

		try {
			HttpClients.createDefault().execute(new HttpGet(
					"http://127.0.0.1:8080/xxx/002?countNumber=" + ((int) (Math.random() * 10) + 1)))
					.close();

		} catch (IOException e) {
			e.printStackTrace();
		}
	}
}


用到的jar包:

commons-logging-1.1.3.jar

httpclient-4.3.1.jar

httpclient-cache-4.2.5.jar

httpcore-4.3.2.jar

httpmime-4.3.5.jar


转载于:https://my.oschina.net/zuodev/blog/668872

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值