• Post Reply Bookmark Topic Watch Topic
  • New Topic

Select vs. multiple threads...

 
Marc Nurmi
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.
 
Pho Tek
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...
 
Ron Hitchens
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.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!