M
meselfo
I have an object attached to all selectionKeys with a timestamp
showing last activity
on the connection. So how/when do i run through the keys to find
connections
that have been idle too long? Can i do it in the same main selector
loop that handles accept/read etc like this:
while (true) {
selector.select(sometimeout);
Iterator selectedKeys = selector.selectedKeys().iterator();
while (selectedKeys.hasNext()) {
..process the selected key... accept/read etc..
}
if (timeToCheckForIdleConnections) {
Set<SelectionKey> k = selector.keys();
.. get attachment of all keys and check their timestamp for last
activity.. if idle for too long then close them!
}
}
or should I use a timethread that signals back to the main selector
thread which connections to close?
showing last activity
on the connection. So how/when do i run through the keys to find
connections
that have been idle too long? Can i do it in the same main selector
loop that handles accept/read etc like this:
while (true) {
selector.select(sometimeout);
Iterator selectedKeys = selector.selectedKeys().iterator();
while (selectedKeys.hasNext()) {
..process the selected key... accept/read etc..
}
if (timeToCheckForIdleConnections) {
Set<SelectionKey> k = selector.keys();
.. get attachment of all keys and check their timestamp for last
activity.. if idle for too long then close them!
}
}
or should I use a timethread that signals back to the main selector
thread which connections to close?