Class NioUtil


  • public class NioUtil
    extends java.lang.Object
    General utilities for NIO
    • Constructor Summary

      Constructors 
      Constructor Description
      NioUtil()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static java.nio.channels.Selector reduceSelectorGarbage​(java.nio.channels.Selector selector)
      Use reflection to change the collection implementations so iteration operations used in the selector implementation will not produce garbage.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • NioUtil

        public NioUtil()
    • Method Detail

      • reduceSelectorGarbage

        public static java.nio.channels.Selector reduceSelectorGarbage​(java.nio.channels.Selector selector)
        Use reflection to change the collection implementations so iteration operations used in the selector implementation will not produce garbage.

        This is only applied when the system property java.specification.version is equal to "1.8".

        We can do this because, by looking at the source code, we can tell that there are no simultaneous iterations so reusing one iterator is OK. Because of concurrent modification issues and thread safety issues, this is generally likely to be the case anyway. The implementation of selector is not likely to change between minor JDK revisions. A major JDK release might produce a rewrite, but in that case we can check the JDK version and apply the appropriate set of patches.