dcsimg
Login | Register   
LinkedIn
Google+
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX

By submitting your information, you agree that devx.com may send you DevX offers via email, phone and text message, as well as email offers about other products and services that DevX believes may be of interest to you. DevX will process your information in accordance with the Quinstreet Privacy Policy.


Tip of the Day
Language: Java
Expertise: Beginner
Aug 10, 1999

WEBINAR:

On-Demand

Building the Right Environment to Support AI, Machine Learning and Deep Learning


Nonblocking I/O

Question:
Say I have 10 sockets and I want to have a thread which checks for a message from the sockets using their InputStreams. The thread will wait in the first socket until it receives a message in that socket. How can I skip to the next socket when there is no message in the current socket?

Answer:
There is no analog to select() in Java, nor is there true nonblocking I/O. The proper way to check if an InputStream has any data available for reading is to call its available() method and see if it returns a positive value. The proper way to check if a Reader has any data available for reading is to call its ready() method and see if it returns true.

DevX Pro
 
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap
Thanks for your registration, follow us on our social networks to keep up-to-date