Posty

Wyświetlanie postów z kwiecień, 2019

Non Blocking IO vs Blocking IO in simple client-server architecture

Obraz
Non Blocking IO (NIO) API is provided in java.nio package. It offers an alternative approach regarding handling input and output operations. One particular possibility is very interesting - performing non blocking IO operations. We will analyze this by impelmenting a simple client-server application and compare NIO approach with 'classical' blocking IO approach. Before we go through an example lets have a quick reminder of the most important NIO structures: Buffers - containers used to store data.  Channels - represent connections to resources with which we can perform IO operations. Channels use Buffers to read data from an external entity (file, socket etc.) into Buffer or write data into external resource from Buffer.  Selectors - enable taking advantage of non blocking IO operations. They are used together with SelectionKeys.  Lets cut to the chase and have a look at client-server example in classical blocking IO version. As an IO entity we will use sockets whi