Is there epoll equivalent in Java?

后端 未结 2 1119
天命终不由人
天命终不由人 2020-12-04 17:03

Is there an equivalent of Linux epoll in Java?

epoll allows a thread to react to a number of heterogenous events. For instance, I can have a thread that reacts to e

相关标签:
2条回答
  • 2020-12-04 17:20

    Enhancements in Java SE 6

    java.nio

    A new java.nio.channels.SelectorProvider implementation that is based on the Linux epoll event notification facility is included. The epoll facility is available in the Linux 2.6, and newer, kernels. The new epoll-based SelectorProvider implementation is more scalable than the traditional poll-based SelectorProvider implementation when there are thousands of SelectableChannels registered with a Selector. The new SelectorProvider implementation will be used by default when the 2.6 kernel is detected. The poll-based SelectorProvider will be used when a pre-2.6 kernel is detected.

    https://docs.oracle.com/javase/8/docs/technotes/guides/io/enhancements.html

    0 讨论(0)
  • 2020-12-04 17:46

    Yes, the nio package allows the use of Selectors which supply the functionality equivalent of poll()/select() and actually one of the implementations uses epoll as the backend (this is selected via java.nio.channels.spi.SelectorProvider Java property). Selectors are usually used with network sockets, but if you look through the different Channel implementations in the docs, I think it's likely you will be able to use this mechanism with standard input as well (there are helper classes which allow moving between old Stream-based APIs and the nio APIs to some degree).

    0 讨论(0)
提交回复
热议问题