请问我的服务器既要处理用户并发的请求有要长连接到另一个服务器上这个要怎么操作

创新移动 发布于 2012/07/03 17:26
阅读 585
收藏 0

  serverfactory = new NioServerSocketChannelFactory(Executors.newCachedThreadPool(), Executors.newCachedThreadPool());
        ServerBootstrap bootstrap = new ServerBootstrap(serverfactory);
        bootstrap.setPipelineFactory(new ChannelPipelineFactory()
        {
            public ChannelPipeline getPipeline()
            {
             return Channels.pipeline(new HeaderFrameDecoder(), new GameServerHandler());
            }
        });

        bootstrap.setOption("child.tcpNoDelay", true);
        bootstrap.setOption("child.keepAlive", true);
        Channel channel = bootstrap.bind(new InetSocketAddress(Config.getServerPort()));
        allChannels.add(channel);

 

  if(clientfactory == null)
  {
   clientfactory = new NioClientSocketChannelFactory(Executors.newSingleThreadExecutor(),Executors.newSingleThreadExecutor());
  }
     ClientBootstrap bootstrap = new ClientBootstrap(clientfactory);
     bootstrap.setPipelineFactory(new ChannelPipelineFactory()
     {
         public ChannelPipeline getPipeline()
         {
          return Channels.pipeline(new HeaderFrameDecoder(), new DatabaseClientHandler());
         }
     });
     
     bootstrap.setOption("tcpNoDelay", true);
     ChannelFuture future = bootstrap.connect(new InetSocketAddress(Config.getDatabaseHost(), Config.getDatabasePort()));
     future = future.awaitUninterruptibly();
     databaseChannel = future.getChannel();
     lastDbConnectTime = System.currentTimeMillis();

 

这个Executor使用的正确吗?

加载中
0
创新移动

还有个问题就是我最后调用

  if(clientfactory != null)
  {
   ChannelFuture future = databaseChannel.close();
   future.awaitUninterruptibly();
   clientfactory.releaseExternalResources();
  }

clientfactory.releaseExternalResources();
卡住了,什么原因

返回顶部
顶部