concurrent connection using Java NIO -


the general outline of problem clientsocketchannel multithreading use cpu more expected. general thing clientsocketchannel multithreading. ok, should question going ask asked before in this question.

there other posts same answers. reason mentioned again cannot understand answers not obvious , cannot adopt code them. try briefly explain requirement see if there answer can cover whole requirements.

  1. the write process should trigger bytebuffer fill in thread
  2. the system have conscious of either write or read operation, of them happen first.
  3. a way prevent useless cpu running seems op_write make busy when not required.

answer:

the correct way use op_write follows:

register newly accepted channel op_read only

so need 1 channel op_read operand or both (channel1 op_read, channel2 op_read | op_write)?

when have write channel, write it

in part of code?

if write returns zero, register channel op_write, save bytebuffer trying write, , return select loop when op_write fires on channel, call write() same buffer if write succeeds , doesn't return zero, register op_read again, or @ least remove op_write interestops.

"if write returns zero" far knowledge means no byte write, why should register op_write?

"save byte buffer": true put buffer third argument of register? below?

  channel.register(selector, operations, sharedbuffer); 

the write process should trigger bytebuffer fill in thread

why? other thread can actual write. don't need 'trigger' anything.

the system have conscious of either write or read operation, of them happen first.

no problem.

a way prevent useless cpu running seems op_write make busy when not required.

correct. op_write ready, using when don't have pending data write which has failed going smoke cpu.

so need 1 channel op_read operand or both (channel1 op_read, channel2 op_read | op_write)?

you need 1 channel.

in part of code?

in part knows has write.

"if write returns zero" far knowledge means no byte write,

no doesn't. see javadoc. means nothing written. if there 'no byte write' wouldn't have called write() in first place.

so why should register op_write?

so can told when channel becomes writable.

"save byte buffer": true put buffer third argument of register? below?

yes.


Comments

Popular posts from this blog

sql server - Cannot query correctly (MSSQL - PHP - JSON) -

php - trouble displaying mysqli database results in correct order -

C++ Linked List -