java - Trouble synchronizing threads with Apache Mina -


I am using Apache Meena 1.1.7 and Java 1.6. Server sends sequence of three messages to the client in the loop Sometimes two sets of messages overlap, for example, I hope:

  ++ recv: MSGHEAD ++ recv: message body 1++ recv:. ++ recv: MSGHEAD ++ recv: message body 2++ recv:.  

But I get this instead:

  ++ recv: MSGHEAD ++ recv: MSGHEAD ++ recv: Message Body 1 ++ recv: . ++ recv: message body 2++ recv:.  

This is my server configuration:

  Socket Exceptor acceptor = new socket attachment (); Socket Except Config Config = Configure New Socket Accelerator (); Config.setThreadModel (ThreadModel.MANUAL); If (true) {SSLContextFactory factory = new SSLContextFactory (); Config.getFilterChain () AddLast ("sslFilter", new SSLFilter (factory.getInstance (true)); } System.out.println (config.getFilterChain (.) ToString ()); Config.getFilterChain () AddLast ( "codec", new Protocolkodekfiltr (new Tekstlainkodkfaktayr (Varnsetkfeyrnam ( "UTF -8"))); Config.getFilterChain (). AddLast ( "the message" New ToMessageIoFilter ()); Config.getSessionConfig () . SetReuseAddress (true);. Config.getSessionConfig () setTcpNoDelay (right); Acceptor.bind (new InetSocketAddress (PORT), new MinaServerHandler (new MinaConnectionFactory ()), config);}  

sends here the sequence of how messages I:

  send public void message (string msg) IOException throws synchronized {(session) {writeLine ( "MSGHEAD"); WriteLine (MSG); line Write (".");}} Private Zero writing line (string line) {WriteFuture w = session.write (line);}  

What am I doing?

< / div>

If three threads in loops sendMessage () in each, so that you can expect sometimes lines are to output them, sometimes not. When you describe what behavior.

I see that you have attempted to synchronize threads so that all messages of To complete block output. So what might be wrong is that each thread has its own session object, your threads should share the object to which they are synchronized.

The easiest way to remove synchronized statements and remove sendMessage () a. Although it can not be very fast.


Comments

Popular posts from this blog

c# - How to capture HTTP packet with SharpPcap -

jquery - SimpleModal Confirm fails to submit form -

php - Multiple Select with Explode: only returns the word "Array" -