我正在实现ChannelInboundHandlerAdapter
,并且有一个关于并发的问题。是否需要使其线程安全?我的意思是,我必须为每个客户端存储一些状态以便于他们的会话。
public class Impl extends ChannelInboundHandlerAdapter{
private List<Integer> someState;
//
public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
int size = someState.size(); //Should I worry about memory consitency here?
//...
}
}
问题是,如果每个请求之间的channelRead
方法由不同的线程调用,我将不得不设置一些内存屏障。
这是必需的吗?还是Netty
自己会处理?