J
Jeff Silvis
At:
http://www.javanio.info/filearea/bo...ronsoft/books/nio/channels/SelectSockets.java
There is sample code. In that page there are the lines:
// send the data, don't assume it goes all at once
while (buffer.hasRemaining()) {
socketChannel.write (buffer);
}
// WARNING: the above loop is evil. Because
// it's writing back to the same non-blocking
// channel it read the data from, this code can
// potentially spin in a busy loop. In real life
// you'd do something more useful than this.
In some of my code I have written a line more or less exactly like:
while (buffer.hasRemaining()) {
socketChannel.write (buffer);
}
and the code does just spin. What is an example of "something more
useful than this"?
Jeff
http://www.javanio.info/filearea/bo...ronsoft/books/nio/channels/SelectSockets.java
There is sample code. In that page there are the lines:
// send the data, don't assume it goes all at once
while (buffer.hasRemaining()) {
socketChannel.write (buffer);
}
// WARNING: the above loop is evil. Because
// it's writing back to the same non-blocking
// channel it read the data from, this code can
// potentially spin in a busy loop. In real life
// you'd do something more useful than this.
In some of my code I have written a line more or less exactly like:
while (buffer.hasRemaining()) {
socketChannel.write (buffer);
}
and the code does just spin. What is an example of "something more
useful than this"?
Jeff