mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
organize "Javac server event loop" threads in pool and wait for their termination
By default Netty just creates threads light and right and abandons them (see io.netty.util.concurrent.ThreadPerTaskExecutor WTF?)
This commit is contained in:
@@ -50,6 +50,7 @@ import java.io.File;
|
||||
import java.net.InetAddress;
|
||||
import java.net.UnknownHostException;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.ThreadPoolExecutor;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@@ -72,6 +73,7 @@ public class ExternalJavacManager {
|
||||
private final Map<UUID, JavacProcessDescriptor> myMessageHandlers = new HashMap<>();
|
||||
private int myListenPort = DEFAULT_SERVER_PORT;
|
||||
private final Set<ProcessHandler> myRunningHandlers = ContainerUtil.newConcurrentSet();
|
||||
private final ThreadPoolExecutor myExecutor = ConcurrencyUtil.newSingleThreadExecutor("Javac server event loop pool");
|
||||
|
||||
public ExternalJavacManager(@NotNull final File workingDir) {
|
||||
myWorkingDir = workingDir;
|
||||
@@ -81,7 +83,7 @@ public class ExternalJavacManager {
|
||||
public void start(int listenPort) {
|
||||
final ChannelHandler compilationRequestsHandler = new CompilationRequestsHandler();
|
||||
final ServerBootstrap bootstrap = new ServerBootstrap()
|
||||
.group(new NioEventLoopGroup(1, ConcurrencyUtil.newNamedThreadFactory("Javac server event loop")))
|
||||
.group(new NioEventLoopGroup(1, myExecutor))
|
||||
.channel(NioServerSocketChannel.class)
|
||||
.childOption(ChannelOption.TCP_NODELAY, true)
|
||||
.childOption(ChannelOption.SO_KEEPALIVE, true)
|
||||
@@ -187,6 +189,12 @@ public class ExternalJavacManager {
|
||||
if (!handler.waitFor(unit.toMillis(time))) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
try {
|
||||
myExecutor.awaitTermination(time, unit);
|
||||
}
|
||||
catch (InterruptedException ignored) {
|
||||
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@@ -209,6 +217,7 @@ public class ExternalJavacManager {
|
||||
|
||||
public void stop() {
|
||||
myChannelRegistrar.close().awaitUninterruptibly();
|
||||
myExecutor.shutdownNow();
|
||||
}
|
||||
|
||||
private ExternalJavacProcessHandler launchExternalJavacProcess(UUID uuid,
|
||||
|
||||
Reference in New Issue
Block a user