diff --git a/java/compiler/impl/src/com/intellij/compiler/server/BuildManager.java b/java/compiler/impl/src/com/intellij/compiler/server/BuildManager.java index d86be2d6acb1..4a3e60982702 100644 --- a/java/compiler/impl/src/com/intellij/compiler/server/BuildManager.java +++ b/java/compiler/impl/src/com/intellij/compiler/server/BuildManager.java @@ -128,7 +128,7 @@ public class BuildManager implements ApplicationComponent{ private final ChannelGroup myAllOpenChannels = new DefaultChannelGroup("build-manager"); private final BuildMessageDispatcher myMessageDispatcher = new BuildMessageDispatcher(); - private int myListenPort = -1; + private volatile int myListenPort = -1; private volatile CmdlineRemoteProto.Message.ControllerMessage.GlobalSettings myGlobals; public BuildManager(final ProjectManager projectManager) { @@ -380,7 +380,11 @@ public class BuildManager implements ApplicationComponent{ // ensure server is listening if (myListenPort < 0) { try { - myListenPort = startListening(); + synchronized (this) { + if (myListenPort < 0) { + myListenPort = startListening(); + } + } } catch (Exception e) { handler.handleFailure(sessionId, CmdlineProtoUtil.createFailure(e.getMessage(), null)); @@ -795,7 +799,7 @@ public class BuildManager implements ApplicationComponent{ } private int startListening() throws Exception { - final ChannelFactory channelFactory = new NioServerSocketChannelFactory(myPooledThreadExecutor, myPooledThreadExecutor); + final ChannelFactory channelFactory = new NioServerSocketChannelFactory(myPooledThreadExecutor, myPooledThreadExecutor, Math.min(4, Math.max(2, Runtime.getRuntime().availableProcessors()))); final SimpleChannelUpstreamHandler channelRegistrar = new SimpleChannelUpstreamHandler() { public void channelOpen(ChannelHandlerContext ctx, ChannelStateEvent e) throws Exception { myAllOpenChannels.add(e.getChannel());