0
我是netty.io的新手。我试图编写一个应用程序,在客户端第一次连接时插入超过200行。问题是一次只插入10行,看起来像netty只是打断了我的代码。我无法弄清楚如何为我的任务设置最大执行时间。如何在netty中执行长任务?
这是怎么了,我开始服务器:
public void start() throws InterruptedException{
EventLoopGroup group = new NioEventLoopGroup();
EventExecutorGroup sqlExecutorGroup = new DefaultEventExecutorGroup(10);
ServerBootstrap server = new ServerBootstrap();
server.group(group);
server.channel(NioServerSocketChannel.class);
server.localAddress(new InetSocketAddress(port));
server.childHandler(new ChannelInitializer<SocketChannel>(){
@Override
protected void initChannel(SocketChannel ch) throws Exception {
ch.pipeline().addLast(new HttpServerCodec());
ch.pipeline().addLast(new ChunkedWriteHandler());
ch.pipeline().addLast(new HttpObjectAggregator(65536));
ch.pipeline().addLast(new WebSocketServerProtocolHandler("/"));
ch.pipeline().addLast(new WebSocketFrameToByteBuf());
ch.pipeline().addLast(new ProtobufEncoder());
ch.pipeline().addLast(new ProtobufDecoder(Chat.MsgWrapper.getDefaultInstance()));
ch.pipeline().addLast(new MsgUserLogin(prop.getProperty("sessions_prefix")));
}
});
ChannelFuture f = server.bind().sync();
f.channel().closeFuture().sync();
}
这是IM执行任务的处理程序中的功能:
private void register(ChannelHandlerContext ctx, Chat.User u){
ctx.executor().execute(new Runnable() {
@Override
public void run() {
ctx.channel().attr(Main.KeyUser).set(u);
ConversationUserMember member = ConversationPool.getOrCacheConversationUserMember(u);
ConversationPool.UpdateConversations(member);
Main.loggedUsers.add(ctx.channel());
member.newChannel(ctx.channel());
returnConversations(member,ctx); //this function is the one getting cut by netty.
// fireNewUser(u);
}
});
}