langtools/test/tools/sjavac/PooledExecution.java
changeset 32335 7df616378cf3
parent 30730 d3ce7619db2c
child 32337 c9d3ab9f601c
equal deleted inserted replaced
32334:fd65e32e16b3 32335:7df616378cf3
    30  * @modules jdk.compiler/com.sun.tools.sjavac.comp
    30  * @modules jdk.compiler/com.sun.tools.sjavac.comp
    31  *          jdk.compiler/com.sun.tools.sjavac.server
    31  *          jdk.compiler/com.sun.tools.sjavac.server
    32  * @build Wrapper
    32  * @build Wrapper
    33  * @run main Wrapper PooledExecution
    33  * @run main Wrapper PooledExecution
    34  */
    34  */
    35 import java.io.File;
       
    36 import java.net.URI;
       
    37 import java.util.Collections;
       
    38 import java.util.List;
       
    39 import java.util.Set;
       
    40 import java.util.concurrent.CountDownLatch;
    35 import java.util.concurrent.CountDownLatch;
    41 import java.util.concurrent.atomic.AtomicInteger;
    36 import java.util.concurrent.atomic.AtomicInteger;
    42 
    37 
    43 import com.sun.tools.sjavac.comp.PooledSjavac;
    38 import com.sun.tools.sjavac.comp.PooledSjavac;
    44 import com.sun.tools.sjavac.server.CompilationResult;
    39 import com.sun.tools.sjavac.server.CompilationResult;
    45 import com.sun.tools.sjavac.server.Sjavac;
    40 import com.sun.tools.sjavac.server.Sjavac;
    46 import com.sun.tools.sjavac.server.SysInfo;
       
    47 
    41 
    48 
    42 
    49 public class PooledExecution {
    43 public class PooledExecution {
    50 
    44 
    51     public static void main(String[] args) throws InterruptedException {
    45     public static void main(String[] args) throws InterruptedException {
    73             final AtomicInteger tasksFinished = new AtomicInteger(0);
    67             final AtomicInteger tasksFinished = new AtomicInteger(0);
    74 
    68 
    75             for (int i = 0; i < NUM_REQUESTS; i++) {
    69             for (int i = 0; i < NUM_REQUESTS; i++) {
    76                 tasks[i] = new Thread() {
    70                 tasks[i] = new Thread() {
    77                     public void run() {
    71                     public void run() {
    78                         service.compile("",
    72                         service.compile(new String[0]);
    79                                         "",
       
    80                                         new String[0],
       
    81                                         Collections.<File>emptyList(),
       
    82                                         Collections.<URI>emptySet(),
       
    83                                         Collections.<URI>emptySet());
       
    84                         tasksFinished.incrementAndGet();
    73                         tasksFinished.incrementAndGet();
    85                     }
    74                     }
    86                 };
    75                 };
    87                 tasks[i].start();
    76                 tasks[i].start();
    88             }
    77             }
   120 
   109 
   121             // Keeps track of currently active requests
   110             // Keeps track of currently active requests
   122             AtomicInteger activeRequests = new AtomicInteger(0);
   111             AtomicInteger activeRequests = new AtomicInteger(0);
   123 
   112 
   124             @Override
   113             @Override
   125             public CompilationResult compile(String protocolId,
   114             public CompilationResult compile(String[] args) {
   126                                              String invocationId,
       
   127                                              String[] args,
       
   128                                              List<File> explicitSources,
       
   129                                              Set<URI> sourcesToCompile,
       
   130                                              Set<URI> visibleSources) {
       
   131                 leftToStart.countDown();
   115                 leftToStart.countDown();
   132                 int numActiveRequests = activeRequests.incrementAndGet();
   116                 int numActiveRequests = activeRequests.incrementAndGet();
   133                 System.out.printf("Left to start: %2d / Currently active: %2d%n",
   117                 System.out.printf("Left to start: %2d / Currently active: %2d%n",
   134                                   leftToStart.getCount(),
   118                                   leftToStart.getCount(),
   135                                   numActiveRequests);
   119                                   numActiveRequests);
   143                 System.out.println("Task completed");
   127                 System.out.println("Task completed");
   144                 return null;
   128                 return null;
   145             }
   129             }
   146 
   130 
   147             @Override
   131             @Override
   148             public SysInfo getSysInfo() {
       
   149                 return null;
       
   150             }
       
   151 
       
   152             @Override
       
   153             public void shutdown() {
   132             public void shutdown() {
   154             }
       
   155 
       
   156             @Override
       
   157             public String serverSettings() {
       
   158                 return "";
       
   159             }
   133             }
   160         }
   134         }
   161     }
   135     }
   162 }
   136 }