• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Non blocking socket in NIO

 
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
what is the concept behind non blocking sockets in NIO package of java?
 
author
Posts: 14112
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Moving to IO and Streams...
 
Ranch Hand
Posts: 1646
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You can find great tutorials on using NIO by searching Google. I did one from IBM's DeveloperWorks, and it was pretty complete.

The main concept is that non-blocking sockets don't block when no data is available to read or the buffer is too full to write. That's it in a nut shell.

Normally, if you have a server that handles multiple requests simultaneously, with blocking I/O you're forced to use a separate thread for each request. If you want to handle 1000 clients at once, you need 1000 threads. Since the majority of time the threads are blocked waiting on I/O operations, this is a huge waste of resources.

With non-blocking I/O, you can have one thread handle all the requests. The thread loops checking a bunch of sockets at once for available data rather than blocking on a single socket.
 
I'm not sure if I approve of this interruption. But this tiny ad checks out:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic