users@tyrus.java.net

Re: MessageHandler is thread safe it?

From: Pavel Bucek <pavel.bucek_at_oracle.com>
Date: Sat, 20 Sep 2014 15:17:41 +0200

Message handler is user code, so we cannot really state that it is
thread safe - that depends.

What we can state is that no other message handler will be invoked
before processing previous message - meaning that message handlers are
always called sequentially. "Problem" is that we don't guarantee that
the call will be done from the same thread - so processing of message M1
can lead to invocation of your message handler from Thread T1 and when
next message is received, message handler would be invoked with message
M2 from thread T2.

Hope it answered your question.

Regards,
Pavel

On 20/09/14 14:39, 张立鑫 wrote:
> Can i do this:
>
> session.addMessageHandler(new MessageHandler.Partial<byte[]>() {
>
> @Override
> public void onMessage(byte[] partialMessage, boolean last) {
> EendpoitProxy.this.message = partialMessage;
> session.sendObject(processHandler());
> }
> });
>
> processHandler(){
> // invoke original method
> }