Cancels this key.
If this key has not yet been cancelled then it is added to its
selector's cancelled-key set while synchronized on that set.
// Synchronizing "this" to prevent this key from getting canceled
// multiple times by different threads, which might cause race
// condition between selector's select() and channel's close().
synchronized (this) {
if (valid) {
valid = false;
((AbstractSelector)selector()).cancel(this);
}
}