首页 > 代码库 > Java实现多线程并发
Java实现多线程并发
1 import java.util.concurrent.ExecutorService; 2 import java.util.concurrent.Executors; 3 import java.util.concurrent.Semaphore; 4 5 public class ThreadTest { 6 private static int thread_num = 500; 7 private static int client_num = 5000; 8 9 public static void main(String[] args,String no) {10 ExecutorService exec = Executors.newCachedThreadPool();11 12 final Semaphore semp = new Semaphore(thread_num);13 14 for (int index = 0; index < client_num; index++) {15 16 final int NO = index;17 18 Runnable run = new Runnable() {19 public void run() {20 try {21 semp.acquire();22 //HttpClientTest.postLogin();23 System.out.println("Thread:" + NO);24 semp.release();25 } catch (Exception e) {26 e.printStackTrace();27 }28 }29 };30 exec.execute(run);31 }32 exec.shutdown();33 }34 }
Java实现多线程并发
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。