langtools/src/jdk.compiler/share/classes/com/sun/tools/sjavac/comp/PooledSjavac.java
changeset 32335 7df616378cf3
parent 31115 8d8e98052d5d
child 32542 f4e4f4c4f9f4
equal deleted inserted replaced
32334:fd65e32e16b3 32335:7df616378cf3
    22  * or visit www.oracle.com if you need additional information or have any
    22  * or visit www.oracle.com if you need additional information or have any
    23  * questions.
    23  * questions.
    24  */
    24  */
    25 package com.sun.tools.sjavac.comp;
    25 package com.sun.tools.sjavac.comp;
    26 
    26 
    27 import java.io.File;
       
    28 import java.net.URI;
       
    29 import java.util.List;
       
    30 import java.util.Objects;
    27 import java.util.Objects;
    31 import java.util.Set;
       
    32 import java.util.concurrent.ExecutorService;
    28 import java.util.concurrent.ExecutorService;
    33 import java.util.concurrent.Executors;
    29 import java.util.concurrent.Executors;
    34 import java.util.concurrent.TimeUnit;
    30 import java.util.concurrent.TimeUnit;
    35 
    31 
    36 import com.sun.tools.sjavac.Log;
    32 import com.sun.tools.sjavac.Log;
    37 import com.sun.tools.sjavac.server.CompilationResult;
    33 import com.sun.tools.sjavac.server.CompilationResult;
    38 import com.sun.tools.sjavac.server.Sjavac;
    34 import com.sun.tools.sjavac.server.Sjavac;
    39 import com.sun.tools.sjavac.server.SysInfo;
       
    40 
    35 
    41 /**
    36 /**
    42  * An sjavac implementation that limits the number of concurrent calls by
    37  * An sjavac implementation that limits the number of concurrent calls by
    43  * wrapping invocations in Callables and delegating them to a FixedThreadPool.
    38  * wrapping invocations in Callables and delegating them to a FixedThreadPool.
    44  *
    39  *
    57         this.delegate = delegate;
    52         this.delegate = delegate;
    58         pool = Executors.newFixedThreadPool(poolsize);
    53         pool = Executors.newFixedThreadPool(poolsize);
    59     }
    54     }
    60 
    55 
    61     @Override
    56     @Override
    62     public SysInfo getSysInfo() {
    57     public CompilationResult compile(String[] args) {
    63         try {
       
    64             return pool.submit(() -> delegate.getSysInfo()).get();
       
    65         } catch (Exception e) {
       
    66             e.printStackTrace();
       
    67             throw new RuntimeException("Error during getSysInfo", e);
       
    68         }
       
    69     }
       
    70 
       
    71     @Override
       
    72     public CompilationResult compile(final String protocolId,
       
    73                                      final String invocationId,
       
    74                                      final String[] args,
       
    75                                      final List<File> explicitSources,
       
    76                                      final Set<URI> sourcesToCompile,
       
    77                                      final Set<URI> visibleSources) {
       
    78         try {
    58         try {
    79             return pool.submit(() -> {
    59             return pool.submit(() -> {
    80                 return delegate.compile(protocolId,
    60                 return delegate.compile(args);
    81                                         invocationId,
       
    82                                         args,
       
    83                                         explicitSources,
       
    84                                         sourcesToCompile,
       
    85                                         visibleSources);
       
    86             }).get();
    61             }).get();
    87         } catch (Exception e) {
    62         } catch (Exception e) {
    88             e.printStackTrace();
    63             e.printStackTrace();
    89             throw new RuntimeException("Error during compile", e);
    64             throw new RuntimeException("Error during compile", e);
    90         }
    65         }
   110         }
    85         }
   111 
    86 
   112         delegate.shutdown();
    87         delegate.shutdown();
   113     }
    88     }
   114 
    89 
   115     @Override
       
   116     public String serverSettings() {
       
   117         return delegate.serverSettings();
       
   118     }
       
   119 }
    90 }