Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
596 views
in Technique[技术] by (71.8m points)

multithreading - Is there epoll equivalent in Java?

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 either a socket event or an input from the console. In C++ I can implement this by registering stdio and the socket with epoll. My thread will be triggered by an event from either if these.

Is there a similar facility in Java? I looked at the nio package, it allows me to register a number of sockets with a selector. But there does not seem to be away to register the console / standard io with a selector. Am I not seeing something? Is there another way to do this?

On the "why": I want to write a program that communicates via sockets, and i want to drive this program by entering commands from console. I know how this can be done by separating console input and the communications to different threads, but i am curious whether there is a way to do this in a single thread.

Thanks. df

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...