| Author |
NIO Selector - single threaded use
|
Pho Tek
Ranch Hand
Joined: Nov 05, 2000
Posts: 757
|
|
My java class, Foo, will create a non-blocking SocketChannel to a network service. I save the SocketChannel to a member variable. Foo can perform two operations: opA() and opB(). Inside opA() and opB() I will do something like this: The question I have is this: if opA and opB are using the same SocketChannel, do I need to do any synchronization on the methods ? The reason I'm asking is because I've heard that Async I/O will allow me to dispense with creating multiple threads and multiple connections by multiplexing everything on a single connection. Please enlighten me. Thanks Pho
|
Regards,
Pho
|
 |
Jose Botella
Ranch Hand
Joined: Jul 03, 2001
Posts: 2120
|
|
nio package won't dispense you from creating multiple connections, but from creating multiple threads. You could even have a single thread ready for reading/writing to multiple connections, and waiting for the the pending connections to a ServerSocketChannel to be accepted; all of these as indicated by a Selector. Please read the NIO examples provided in the SDK Documentation. The book The JDK1.4 Tutorial by Gregory M. Travis has also a chapter about NIO in which a server example appears. [ March 30, 2004: Message edited by: Jose Botella ]
|
SCJP2. Please Indent your code using UBB Code
|
 |
 |
|
|
subject: NIO Selector - single threaded use
|
|
|