diff --git a/java/execution/impl/src/com/intellij/execution/runners/ProcessProxyFactoryImpl.java b/java/execution/impl/src/com/intellij/execution/runners/ProcessProxyFactoryImpl.java index 04d68ae16212..78c43c68b465 100644 --- a/java/execution/impl/src/com/intellij/execution/runners/ProcessProxyFactoryImpl.java +++ b/java/execution/impl/src/com/intellij/execution/runners/ProcessProxyFactoryImpl.java @@ -23,6 +23,7 @@ import com.intellij.execution.process.ProcessHandler; import com.intellij.openapi.application.PathManager; import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.projectRoots.ex.JavaSdkUtil; +import com.intellij.openapi.util.text.StringUtil; import com.intellij.rt.execution.application.AppMain; import java.io.File; @@ -41,7 +42,7 @@ public class ProcessProxyFactoryImpl extends ProcessProxyFactory { if (moduleName == null || new File(rtJarPath).isFile()) { try { - ProcessProxyImpl proxy = new ProcessProxyImpl(); + ProcessProxyImpl proxy = new ProcessProxyImpl(StringUtil.getShortName(mainClass)); String port = String.valueOf(proxy.getPortNumber()); String binPath = PathManager.getBinPath(); diff --git a/java/execution/impl/src/com/intellij/execution/runners/ProcessProxyImpl.java b/java/execution/impl/src/com/intellij/execution/runners/ProcessProxyImpl.java index 82a359ce3dd7..771519095fa4 100644 --- a/java/execution/impl/src/com/intellij/execution/runners/ProcessProxyImpl.java +++ b/java/execution/impl/src/com/intellij/execution/runners/ProcessProxyImpl.java @@ -30,9 +30,11 @@ import java.io.IOException; import java.net.InetSocketAddress; import java.net.StandardSocketOptions; import java.nio.ByteBuffer; +import java.nio.channels.AsynchronousChannelGroup; import java.nio.channels.AsynchronousServerSocketChannel; import java.nio.channels.AsynchronousSocketChannel; import java.nio.channels.CompletionHandler; +import java.util.concurrent.TimeUnit; /** * @author ven @@ -40,20 +42,21 @@ import java.nio.channels.CompletionHandler; class ProcessProxyImpl implements ProcessProxy { static final Key KEY = Key.create("ProcessProxyImpl"); - private final AsynchronousServerSocketChannel myChannel; + private final AsynchronousChannelGroup myGroup; private final int myPort; private final Object myLock = new Object(); private AsynchronousSocketChannel myConnection; private int myPid; - ProcessProxyImpl() throws IOException { - myChannel = AsynchronousServerSocketChannel.open() + ProcessProxyImpl(String mainClass) throws IOException { + myGroup = AsynchronousChannelGroup.withFixedThreadPool(1, r -> new Thread(r, "Process Proxy: " + mainClass)); + AsynchronousServerSocketChannel channel = AsynchronousServerSocketChannel.open(myGroup) .bind(new InetSocketAddress("127.0.0.1", 0)) .setOption(StandardSocketOptions.SO_REUSEADDR, true); - myPort = ((InetSocketAddress)myChannel.getLocalAddress()).getPort(); + myPort = ((InetSocketAddress)channel.getLocalAddress()).getPort(); - myChannel.accept(null, new CompletionHandler() { + channel.accept(null, new CompletionHandler() { @Override public void completed(AsynchronousSocketChannel channel, Void attachment) { synchronized (myLock) { @@ -146,7 +149,10 @@ class ProcessProxyImpl implements ProcessProxy { } } }); - execute(myChannel::close); + execute(() -> { + myGroup.shutdownNow(); + myGroup.awaitTermination(1, TimeUnit.SECONDS); + }); } private static void execute(ThrowableRunnable block) {