码迷,mamicode.com
首页 > 编程语言 > 详细

java高并发测试代码

时间:2019-04-26 20:59:40      阅读:184      评论:0      收藏:0      [点我收藏+]

标签:cat   tar   countdown   start   nal   down   代码   latch   str   

package com.example.test;

import java.net.URL;
import java.net.URLConnection;
import java.util.concurrent.CountDownLatch;

/**
* Created with IDEA
* author:QinWei
* Date:2018/12/27
* Time:11:08
* 并发测试
*/
public class ConnectTest {

public static void main(String[] args) {
int count=1000000;
final CountDownLatch cdl=new CountDownLatch(count);
for (int i = 0; i < count; i++) {
new Thread(new Runnable() {
@Override
public void run() {
cdl.countDown();
try {
cdl.await();
} catch (InterruptedException e) {
e.printStackTrace();
}
try {
connect();
} catch (Exception e) {
e.printStackTrace();
}
}
}).start();
}

}

public static void connect() throws Exception {
final String urlStr="https://blog.52itstyle.com/";
URL url=new URL(urlStr);
URLConnection urlConnection = url.openConnection();
urlConnection.setDoInput(true);
urlConnection.setDoOutput(true);
urlConnection.connect();
System.out.println(urlConnection.getInputStream());
}
}

java高并发测试代码

标签:cat   tar   countdown   start   nal   down   代码   latch   str   

原文地址:https://www.cnblogs.com/zgq123456/p/10776408.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!