equal
deleted
inserted
replaced
1 /* |
1 /* |
2 * Copyright (c) 2014, 2015, Oracle and/or its affiliates. All rights reserved. |
2 * Copyright (c) 2014, 2016, Oracle and/or its affiliates. All rights reserved. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 * |
4 * |
5 * This code is free software; you can redistribute it and/or modify it |
5 * This code is free software; you can redistribute it and/or modify it |
6 * under the terms of the GNU General Public License version 2 only, as |
6 * under the terms of the GNU General Public License version 2 only, as |
7 * published by the Free Software Foundation. |
7 * published by the Free Software Foundation. |
28 * @modules jdk.compiler/com.sun.tools.sjavac.comp |
28 * @modules jdk.compiler/com.sun.tools.sjavac.comp |
29 * jdk.compiler/com.sun.tools.sjavac.server |
29 * jdk.compiler/com.sun.tools.sjavac.server |
30 * @build Wrapper |
30 * @build Wrapper |
31 * @run main Wrapper PooledExecution |
31 * @run main Wrapper PooledExecution |
32 */ |
32 */ |
|
33 import java.io.PrintWriter; |
33 import java.io.Writer; |
34 import java.io.Writer; |
34 import java.util.concurrent.CountDownLatch; |
35 import java.util.concurrent.CountDownLatch; |
35 import java.util.concurrent.atomic.AtomicInteger; |
36 import java.util.concurrent.atomic.AtomicInteger; |
36 |
37 |
|
38 import com.sun.tools.sjavac.Log; |
37 import com.sun.tools.sjavac.comp.PooledSjavac; |
39 import com.sun.tools.sjavac.comp.PooledSjavac; |
38 import com.sun.tools.sjavac.server.Sjavac; |
40 import com.sun.tools.sjavac.server.Sjavac; |
39 |
41 |
40 |
42 |
41 public class PooledExecution { |
43 public class PooledExecution { |
65 final AtomicInteger tasksFinished = new AtomicInteger(0); |
67 final AtomicInteger tasksFinished = new AtomicInteger(0); |
66 |
68 |
67 for (int i = 0; i < NUM_REQUESTS; i++) { |
69 for (int i = 0; i < NUM_REQUESTS; i++) { |
68 tasks[i] = new Thread() { |
70 tasks[i] = new Thread() { |
69 public void run() { |
71 public void run() { |
70 service.compile(new String[0], null, null); |
72 service.compile(new String[0]); |
71 tasksFinished.incrementAndGet(); |
73 tasksFinished.incrementAndGet(); |
72 } |
74 } |
73 }; |
75 }; |
74 tasks[i].start(); |
76 tasks[i].start(); |
75 } |
77 } |
107 |
109 |
108 // Keeps track of currently active requests |
110 // Keeps track of currently active requests |
109 AtomicInteger activeRequests = new AtomicInteger(0); |
111 AtomicInteger activeRequests = new AtomicInteger(0); |
110 |
112 |
111 @Override |
113 @Override |
112 public int compile(String[] args, Writer out, Writer err) { |
114 public int compile(String[] args) { |
113 leftToStart.countDown(); |
115 leftToStart.countDown(); |
114 int numActiveRequests = activeRequests.incrementAndGet(); |
116 int numActiveRequests = activeRequests.incrementAndGet(); |
115 System.out.printf("Left to start: %2d / Currently active: %2d%n", |
117 System.out.printf("Left to start: %2d / Currently active: %2d%n", |
116 leftToStart.getCount(), |
118 leftToStart.getCount(), |
117 numActiveRequests); |
119 numActiveRequests); |