public class ConcurrentTest {
public static void main(String[] args) {
ExecutorService exec = Executors.newFixedThreadPool(30);
for (int index = 0; index < 1000000; index++) {
final int NO = index;
Runnable run = new Runnable() {
public void run() {
try {
long time1=System.currentTimeMillis();
URL url = new URL("https://crazyboy1.com/WX_01/get/azdsaf@3");
InputStreamReader isr = new InputStreamReader(url.openStream());
long time2=System.currentTimeMillis();
System.out.print("Thread "+NO+" time:"+(time2-time1)+"ms");
BufferedReader br = new BufferedReader(isr);
String str;
while ((str = br.readLine()) != null) {
System.out.println(str);
}
br.close();
isr.close();
} catch (Exception e) {
e.printStackTrace();
}
}
};
exec.execute(run);
}
// 退出线程池
exec.shutdown();
}
}
Java模拟并发访问
最新推荐文章于 2024-06-18 06:31:37 发布