-
Sub-task
-
Resolution: Delivered
-
P4
-
11
-
Verified
`java.nio.channels.Selector` historically specified its key set (the set containing the keys representing the channels registered with the selector) to not be thread safe. Selection operations were specified to synchronize on this key set. Additionally, the `register` methods defined by `java.nio.channels.SelectableChannel` (`SocketChannel`, `ServerSocketChannel`, ...) were also specified to synchronize on the selector's key set and therefore block if invoked concurrently with another registration or selection operation.
The specification has changed in Java SE 11 so that the selector's key set is specified to be safe for use by concurrent threads. Selection operations are no longer specified to synchronize on the key set. This allows threads to register channels while a selection operation is in progress; the new registration takes effect at the next selection operation. `SelectionKey` `interestOps(int)` has also been re-specified so that it can be called at any time. If invoked while a selection operation is in progress, then it has no effect upon that operation; the change to the key's interest set will be seen by the next selection operation.
Code that synchronizes on the `Selector`'s selected-key set is not impacted by this change as selection operations continue to be specified to synchronize on the selected-key set.
The `Selector` API is pluggable. `SelectorProvider` implementations that exist outside of the JDK will need to be updated to align their `Selector` implementation with the updated specification.
The specification has changed in Java SE 11 so that the selector's key set is specified to be safe for use by concurrent threads. Selection operations are no longer specified to synchronize on the key set. This allows threads to register channels while a selection operation is in progress; the new registration takes effect at the next selection operation. `SelectionKey` `interestOps(int)` has also been re-specified so that it can be called at any time. If invoked while a selection operation is in progress, then it has no effect upon that operation; the change to the key's interest set will be seen by the next selection operation.
Code that synchronizes on the `Selector`'s selected-key set is not impacted by this change as selection operations continue to be specified to synchronize on the selected-key set.
The `Selector` API is pluggable. `SelectorProvider` implementations that exist outside of the JDK will need to be updated to align their `Selector` implementation with the updated specification.