• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Junilu Lacar
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Ganesh Patekar
  • Tim Moores
  • Pete Letkeman
  • Stephan van Hulst
Bartenders:
  • Carey Brown
  • Tim Holloway
  • Joe Ess

Select vs. multiple threads...  RSS feed

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Given an application that accepts input on multiple sockets, what are the pros/cons of dedicating a thread to each socket vs. using selectors to process input in a single thread? Assume the application can be written either way.
 
Ranch Hand
Posts: 782
Chrome Python Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well imagine that your program is watching for IO from several hundred Channels (this is likely in the case of writing a program to receive data or notification from sensors place in a large factory for example). Thus using a multithread model; you would have a one thread----->one channel design. This doesn't scale.
This article suggests using Selectors for a single thread design by employing the Reactor design pattern
[ April 15, 2003: Message edited by: Pho Tek ]
[ April 15, 2003: Message edited by: Pho Tek ]
 
Marc Nurmi
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Very good article... thanks! Surprised it took so long to get non-blocking I/O into Java. I used the select() call in C many years ago...
 
Author
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Non-blocking and selectors are the primary justification for NIO. Without them, building industrial-strength, enterprise-class applications is tough. Considering that server-side is where Java has really taken root, it is indeed surprising that it didn't happen sooner.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!