@@ -54,7 +54,7 @@ public static void main(String[] args) throws InterruptedException, ExecutionExc
5454 final int elements = 100000 ;
5555 BlockingQueue <Pair <String , Integer >> blockingQueue = new ArrayBlockingQueue <>(50000 );
5656
57- final int concurrency = 20 ;
57+ final int concurrency = 100 ;
5858 ExecutorService threadPool = Executors .newFixedThreadPool (concurrency );
5959
6060 Random r = new Random ();
@@ -83,26 +83,32 @@ public static void main(String[] args) throws InterruptedException, ExecutionExc
8383 // .protocols(Lists.list(Protocol.HTTP_1_1))
8484 .build ();
8585 for (int i = 0 ; i < concurrency ; i ++) {
86+ int finalI = i ;
8687 threadPool .execute (() -> {
8788 try {
8889 while (!threadPool .isTerminated ()) {
8990 Pair <String , Integer > p = blockingQueue .poll (1 , TimeUnit .SECONDS );
9091 if (p == null ) {
9192 break ;
9293 }
93- // final Request request = new Request.Builder()
94- // .addHeader("Authorization", "Bearer " + token.getAccessToken())
95- // .addHeader("Content-Type", "application/json")
96- // .url(ServiceRegion.GCP_EUROPE_WEST1.getApiUrl() + "/" + getProjectKey() + "/messages/"
97- // + p.getLeft())
98- // .build();
99- // try (Response response = client2.newCall(request).execute()) {
100- // String b = response.body().string();
101- // response.close();
102- // System.out.println(b);
103- // System.out.println(p.getRight());
104- // System.out.println(client2.dispatcher().runningCallsCount());
105- // }
94+ final Request request = new Request .Builder ()
95+ // .addHeader("Authorization", "Bearer " + token.getAccessToken())
96+ // .addHeader("Content-Type", "application/json")
97+ .url ("https://jsonapi.org/" )
98+ .get ()
99+ .build ();
100+ try (Response response = client2 .newCall (request ).execute ()) {
101+ String b = response .body ().string ();
102+ response .body ().close ();
103+ response .close ();
104+ System .out .println ("i: " + p .getRight () + "\t s: " + response .code () + "\t r: "
105+ + client2 .dispatcher ().runningCallsCount () + "\t c: "
106+ + client2 .connectionPool ().idleConnectionCount () + "; "
107+ + client2 .connectionPool ().connectionCount ());
108+ }
109+ catch (IOException e ) {
110+ throw new RuntimeException (e );
111+ }
106112
107113 final ApiHttpResponse <byte []> messageApiHttpResponse = client .withProjectKey (getProjectKey ())
108114 .messages ()
0 commit comments