As the title suggests, I'd like to know what is Java's equivalent (or most similar) function to C's poll()
function for polling a set of file descriptors?
Asked
Active
Viewed 2,638 times
12

Maroun
- 94,125
- 30
- 188
- 241

Stephen Walsh
- 815
- 4
- 18
- 34
-
6Package `java.nio` – sujin Feb 06 '14 at 10:46
-
1Will get something here http://stackoverflow.com/questions/15493272/java-poll-on-network-connections – Nidheesh Feb 06 '14 at 10:47
-
I am really interested what will be the exact function in java which will do exactly as C poll. – pmverma Feb 06 '14 at 10:57
-
2What makes you think there is one? There is java.nio.channels.Selector, but nobody said it was exactly the same as poll(). – user207421 Feb 06 '14 at 11:02
-
1@EJP I'm just wondering is there, hence the "(or most similar)". Thanks, java.nio.channels.Selector looks like what I need. – Stephen Walsh Feb 06 '14 at 11:18
-
The Selector only works with network sockets and pipes, but the question is about files. – Dzmitry Lazerka Jul 04 '22 at 11:14
1 Answers
4
As @EJP has commented above for java.nio.channels.Selector
A Selector supports key-based, non-blocking, multiplexed I/O. In other words, selectors enable you to perform I/O through multiple channels. Selectors are most applicable to socket-backed channels.
It is better to take a look at javadoc for java.nio.channels.Selector.
This is available since Java ( 7 ) 1.4 and later

pmverma
- 1,653
- 13
- 27
-
-
1The Selector only works with network sockets and pipes, but the question is about files. – Dzmitry Lazerka Jul 04 '22 at 11:14