import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Semaphore;
public class ThreadTest {
private static int thread_num = 500;
private static int client_num = 5000;
public static void main(String[] args,String no) {
ExecutorService exec = Executors.newCachedThreadPool();
final Semaphore semp = new Semaphore(thread_num);
for (int index = 0; index < client_num; index++) {
final int NO = index;
Runnable run = new Runnable() {
public void run() {
try {
semp.acquire();
//HttpClientTest.postLogin();
System.out.println("Thread:" + NO);
semp.release();
} catch (Exception e) {
e.printStackTrace();
}
}
};
exec.execute(run);
}
exec.shutdown();
}
}
多线程并发demo
最新推荐文章于 2023-03-07 10:18:12 发布