1, nio description and Comparative bio

Nio and bio differences of

bio:

  1. Stream-oriented.
  2. one way.
  3. Obstruction, which is the origin of this b.

nio:

  1. Block-oriented. (Buffer)
  2. Bi-directional.
  3. Non-blocking. Synchronous programming. Select a model

 

Conventional programming step nio

Any data obtained from the channel, will be subject to buffer to store.

  1. Get to the channel. If this is taken from the stream channel, then the channel, only supports one-way.
  2. Construction of Buffer
  3. Data stuffed Buffer, if the write-back operation is executed flip
  4. Read or write back

Buffer usage

  The three core buffer variables, and not a common variable (mark):

  1. mark flag set, note the position of a position, a reset method, which can return
  2. posotion read position, the next position to be read and written.
  3. limit the maximum value of read or write, subscripts next unreadable or non-writable element.
  4. Maximum capacity buffer, and will not become after creation.

 、

Direct memory mapping, zero-copy:

Conventional java flow operation:

  1. Jvm data from the copy to the outside of the heap memory, the jvm, only save the address.
  2. The modified data blocks outside the stack, the writing, reading.
  3. The external heap memory, changes, and then copy back jvm memory.

 When the buffer has a direct memory-mapped buffer, called DirectByteBuffer, by DirectByteBuffer database blocks can be placed directly on the outer jvm heap memory, so that the operation data, the data memory is not necessary to copy from the outer to the jvm heap memory.

 Can map the buffer method call, get an in-memory buffer. Direct operating buffer, equivalent to the original file operations.

Guess you like

Origin www.cnblogs.com/amibandoufu/p/11441528.html