1. /*
  2. * Copyright 2003 Sun Microsystems, Inc. All rights reserved.
  3. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
  4. */
  5. /*
  6. * @(#)InterruptibleChannel.java 1.4 03/01/23
  7. */
  8. package java.nio.channels;
  9. import java.io.IOException;
  10. /**
  11. * A channel that can be asynchronously closed and interrupted.
  12. *
  13. * <p> A channel that implements this interface is <i>asynchronously
  14. * closeable:</i> If a thread is blocked in an I/O operation on an
  15. * interruptible channel then another thread may invoke the channel's {@link
  16. * #close close} method. This will cause the blocked thread to receive an
  17. * {@link AsynchronousCloseException}.
  18. *
  19. * <p> A channel that implements this interface is also <i>interruptible:</i>
  20. * If a thread is blocked in an I/O operation on an interruptible channel then
  21. * another thread may invoke the blocked thread's {@link Thread#interrupt()
  22. * interrupt} method. This will cause the channel to be closed, the blocked
  23. * thread to receive a {@link ClosedByInterruptException}, and the blocked
  24. * thread's interrupt status to be set.
  25. *
  26. * <p> If a thread's interrupt status is already set and it invokes a blocking
  27. * I/O operation upon a channel then the channel will be closed and the thread
  28. * will immediately receive a {@link ClosedByInterruptException}; its interrupt
  29. * status will remain set.
  30. *
  31. * <p> A channel supports asynchronous closing and interruption if, and only
  32. * if, it implements this interface. This can be tested at runtime, if
  33. * necessary, via the <tt>instanceof</tt> operator.
  34. *
  35. *
  36. * @author Mark Reinhold
  37. * @author JSR-51 Expert Group
  38. * @version 1.4, 03/01/23
  39. * @since 1.4
  40. */
  41. public interface InterruptibleChannel
  42. extends Channel
  43. {
  44. /**
  45. * Closes this channel.
  46. *
  47. * <p> Any thread currently blocked in an I/O operation upon this channel
  48. * will receive an {@link AsynchronousCloseException}.
  49. *
  50. * <p> This method otherwise behaves exactly as specified by the {@link
  51. * Channel#close Channel} interface. </p>
  52. *
  53. * @throws IOException If an I/O error occurs
  54. */
  55. public void close() throws IOException;
  56. }