Skip to Main Content

Java APIs

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Hung out on a broken pipe

843790May 20 2009 — edited May 22 2009
One server in our system uses named pipes in Linux to facilitate communications between Java and C processes running on it.

When the pipe, that is read by the Java side, is broken (the C-side process that feeds it is stopped), Java will block trying to instantiate a new FileReader, FileInputStream and RandomAccessFile (in the "r" mode) on that broken pipe. Once blocked, that's it.

My first thought was to create a FileChannel since they are interruptible but you can only get a FileChannel from a FileInputStream or RandomAccessFile and creating those is where the problem is.

In other words, Java seems to be blocking/hanging on the open making it so I can't even get to a read that can be interrupted.

Q1) Any ideas how to keep from blocking on the broken pipe? I can open a java.io.File on the pipe and check exists(), isFile(), length(), canRead() and those all work. length() returns 0, but I'm fairly sure it will do that even if the pipe has content. So those methods won't help.

Q2) If I run the reader in a separate Thread and use my own timeout timer, how do I kill the blocked Thread without resorting to deprecated methods?

Thanks for any thoughts.

Kevin
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jun 19 2009
Added on May 20 2009
6 comments
497 views