Concurrency encoding netty

Will the encoder coding process run at the same time? I observe that the encoding method can be parallel across different threads. A conveyor is defined as:

Channels.pipeline(
    idleHandler,
    new AmfDecoder<GameEvent>(GameEvent.class),
    new AmfEncoder<GameEvent>(),
    concurrencyHandler,
    new WebHandler());

encoder:

public class AmfEncoder<T extends IAmfEvent> extends OneToOneEncoder{
private final SerializationContext serializationContext = new SerializationContext();
private final Amf3Output amfout = new Amf3Output(serializationContext);

@Override
protected Object encode(ChannelHandlerContext arg0, Channel arg1,
        Object arg2) throws Exception {
    T e = (T)arg2;
    ByteArrayOutputStream byteoutStreamSize = new ByteArrayOutputStream();
    amfout.setOutputStream(byteoutStreamSize);
    amfout.writeObject(e.getBody());
    // byteoutStreamSize has small probability become empty at here, in debug mode I can sure e.getBody() has data
    // I thought byteoutStreamSize might be empty by another thread call "amfout.flush()" or "amfout.reset()"
    amfout.flush();
    //...
    amfout.reset();
}

}

The Channel.write call is not only threads belonging to the thread thread or worker threads in the Exeutionhandler. There is a thread pool that itself calls Call.write (). After I moved the 2 variables amfout and serializationContext to the encode () function as a local variable, the problem goes away.

, ChannelPipeline , netty 3.4.5, "", ""... , sendDownstream sendUpstream . , , ExecutionHandler, Channel.write(),

+2
2

, , :

  • () .

  • , ( DownstreamEvents ). OneToOneEncoder Netty. .

  • upstream ( ).

  • Upstream Handlers - ( ).

, - , , .

, . .

+5

, concurrency. :

  • , ( )
  • ChannelPipelineFactory, .
0

All Articles