src/jdk.compiler/share/classes/com/sun/tools/sjavac/comp/PooledSjavac.java
Print this page
rev 2819 : imported patch my-classpath-deps-00
@@ -27,16 +27,13 @@
import java.io.File;
import java.net.URI;
import java.util.List;
import java.util.Objects;
import java.util.Set;
-import java.util.concurrent.Callable;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
-import java.util.concurrent.ThreadFactory;
import java.util.concurrent.TimeUnit;
-import java.util.concurrent.atomic.AtomicInteger;
import com.sun.tools.sjavac.Log;
import com.sun.tools.sjavac.server.CompilationResult;
import com.sun.tools.sjavac.server.Sjavac;
import com.sun.tools.sjavac.server.SysInfo;
@@ -56,32 +53,17 @@
final ExecutorService pool;
public PooledSjavac(Sjavac delegate, int poolsize) {
Objects.requireNonNull(delegate);
this.delegate = delegate;
- pool = Executors.newFixedThreadPool(poolsize, new ThreadFactory() {
- AtomicInteger count = new AtomicInteger();
- @Override
- public Thread newThread(Runnable runnable) {
- String cls = PooledSjavac.class.getSimpleName();
- int num = count.incrementAndGet();
- Thread t = new Thread(runnable, cls + "-" + num);
- t.setDaemon(true);
- return t;
- }
- });
+ pool = Executors.newFixedThreadPool(poolsize);
}
@Override
public SysInfo getSysInfo() {
try {
- return pool.submit(new Callable<SysInfo>() {
- @Override
- public SysInfo call() throws Exception {
- return delegate.getSysInfo();
- }
- }).get();
+ return pool.submit(() -> delegate.getSysInfo()).get();
} catch (Exception e) {
e.printStackTrace();
throw new RuntimeException("Error during getSysInfo", e);
}
}
@@ -92,40 +74,36 @@
final String[] args,
final List<File> explicitSources,
final Set<URI> sourcesToCompile,
final Set<URI> visibleSources) {
try {
- return pool.submit(new Callable<CompilationResult>() {
- @Override
- public CompilationResult call() throws Exception {
+ return pool.submit(() -> {
return delegate.compile(protocolId,
invocationId,
args,
explicitSources,
sourcesToCompile,
visibleSources);
- }
}).get();
} catch (Exception e) {
e.printStackTrace();
throw new RuntimeException("Error during compile", e);
}
}
@Override
public void shutdown() {
+ Log.debug("Shutting down PooledSjavac");
pool.shutdown(); // Disable new tasks from being submitted
try {
// Wait a while for existing tasks to terminate
if (!pool.awaitTermination(60, TimeUnit.SECONDS)) {
pool.shutdownNow(); // Cancel currently executing tasks
// Wait a while for tasks to respond to being cancelled
if (!pool.awaitTermination(60, TimeUnit.SECONDS))
Log.error("ThreadPool did not terminate");
}
- // Grace period for thread termination
- Thread.sleep(1000);
} catch (InterruptedException ie) {
// (Re-)Cancel if current thread also interrupted
pool.shutdownNow();
// Preserve interrupt status
Thread.currentThread().interrupt();