Issue | Fix Version | Assignee | Priority | Status | Resolution | Resolved In Build |
---|---|---|---|---|---|---|
JDK-8205218 | 11.0.1 | Alan Bateman | P4 | Resolved | Fixed | team |
A DESCRIPTION OF THE REQUEST :
This is just a request for either API or documentation enhancement.
In my NIO application, threads often manipulate SelectionKey's interestOps. For example, to clear WRITE interest op, you need to invoke
key.interestOps(key.interestOps() & ~SelectionKey.OP_WRITE)
And this is the place where race problem can occur: if another thread updates interestOps between reading them and setting them.
I don't know if this this is common pitfall, but because interestOps(int) must synchronize somehow, there can be 2 methods to clear interest op:
key.clearInterestOp(int)
and to add interest op:
key.addInterestOp(int)
which will perform reading and writing interest ops atomically.
Or API documentation can be updated with a note showing this pitfall.
JUSTIFICATION :
Spare time of others.
CUSTOMER SUBMITTED WORKAROUND :
For clearing:
synchronized (key) {
key.interestOps(key.interestOps() & ~SelectionKey.OP_WRITE)
}
This is just a request for either API or documentation enhancement.
In my NIO application, threads often manipulate SelectionKey's interestOps. For example, to clear WRITE interest op, you need to invoke
key.interestOps(key.interestOps() & ~SelectionKey.OP_WRITE)
And this is the place where race problem can occur: if another thread updates interestOps between reading them and setting them.
I don't know if this this is common pitfall, but because interestOps(int) must synchronize somehow, there can be 2 methods to clear interest op:
key.clearInterestOp(int)
and to add interest op:
key.addInterestOp(int)
which will perform reading and writing interest ops atomically.
Or API documentation can be updated with a note showing this pitfall.
JUSTIFICATION :
Spare time of others.
CUSTOMER SUBMITTED WORKAROUND :
For clearing:
synchronized (key) {
key.interestOps(key.interestOps() & ~SelectionKey.OP_WRITE)
}
- backported by
-
JDK-8205218 (se) SelectionKey.interestOps variants to atomically update interest ops
-
- Resolved
-
- csr for
-
JDK-8204472 (se) SelectionKey.interestOps variants to atomically update interest ops
-
- Closed
-
- links to