tags:

views:

291

answers:

2

A customer of ours complains that, sporadically, calls of ours to FileChannel.map fail with a ClosedByInterruptException. The Javadoc does not list this as a legitimate possibility. Does anyone know what might be going on here?

Cause0: java.nio.channels.ClosedByInterruptException
Cause0-StackTrace:
at java.nio.channels.spi.AbstractInterruptibleChannel.end(AbstractInterruptibleChannel.java:184)
at sun.nio.ch.FileChannelImpl.map(FileChannelImpl.java:772)
+3  A: 

Channel operations are bound to the thread doing the operations. If this thread is interrupted, the stream / channel is closed due to IO safety issues.

oeogijjowefi
What sort of operations result in such an interrupt? If I wanted to code a test case, what would I have it do? Why can a thread be interrupted in the middle of mapping a file? And what about Claire?
bmargulies
If the application is multi-threaded, you should look for #interrupt()-calls that might interrupt the thread doing the IO operations on the channel. If this is a web-application or some other kind of managed environment, where thread management isn't up to your application (like a Servlet / EJB Container), you should look for thread-safety violations.Another place to look is when the application is shutting down or when thread pooling is used (Servlet/EJB Container!). Then be aware of dynamic management of the pool size!http://java.sun.com/javase/6/docs/api/java/lang/Thread.html#interrupt()
oeogijjowefi
+1  A: 

The last comment contains the answer. There was a thread pool in use, and at shutdown interrupts were delivered.

bmargulies