Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

When you call thread.interrupt(), if a target thread sleeps in a blocking I/O call, this blocking call should throw Java exception.

If target thread does not sleep in a blocking I/O (or uses some kind of unsupported blocking I/O, e.g. implemented with third-party JNI library), only some internal flag sets and no magic happens.

It's pretty simple implementation actually. Thread is not cancelled or corrupted in any way, if you handle this situation, it's perfectly OK to continue execution in this thread. Usually interrupt is used to coordinate termination, indeed, but that's not the only use.

So apparently they didn't find a better way to cancel a blocking I/O operation than just to close file handle from the other thread which causes OS to return some kind of error code from blocking call which translates to Java exception in the end.



Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: