fix "too many nio worker threads" problem

This commit is contained in:
Eugene Zhuravlev
2012-09-06 15:32:10 +02:00
parent ce2b27315f
commit 0498e9ab79
@@ -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());