?
-
Is the while of NIO suppose to be inside a Thread?
public SomeClass() {
...
thread = new Thread(new Runnable() {
while (selector.select() > 0) {
...
if (key.isWritable()) {
socketChannel.write(byteBuffer);
}
...
}
}
thread.start();
}
public void sendData(String string) {
byteBuffer = ByteBuffer.wrap(string.getBytes());
}
If I don't use a thread, calling sendData(..) is to no avail. Am I
missing something?
public SomeClass() {
...
thread = new Thread(new Runnable() {
while (selector.select() > 0) {
...
if (key.isWritable()) {
socketChannel.write(byteBuffer);
}
...
}
}
thread.start();
}
public void sendData(String string) {
byteBuffer = ByteBuffer.wrap(string.getBytes());
}
If I don't use a thread, calling sendData(..) is to no avail. Am I
missing something?