ThreadInterruptedException (Oracle - Berkeley DB Java Edition API)
Date: 2014-12-16

com.sleepycat.je

## Class ThreadInterruptedException

- java.lang.Object
- - java.lang.Throwable
  - - java.lang.Exception
    - - java.lang.RuntimeException
      - - com.sleepycat.je.DatabaseException
        - - com.sleepycat.je.RunRecoveryException
          - - com.sleepycat.je.EnvironmentFailureException
            - - com.sleepycat.je.ThreadInterruptedException

- All Implemented Interfaces:
    Serializable

      public class ThreadInterruptedException
      extends EnvironmentFailureException

  Thrown when `java.lang.InterruptedException` (a thread interrupt) or `java.nio.channels.ClosedChannelException` (which also results from a thread interrupt) occurs in any JE method. This occurs when the application, or perhaps a library or container that the application is using, calls `Thread.interrupt()`.

  Calling `Thread.interrupt` is not recommended for an active JE thread if the goal is to stop the thread or do thread coordination. If you interrupt a thread that is executing a JE operation, the state of the environment will be undefined. That's because JE might have been in the middle of I/O activity when the operation was aborted midstream, and it becomes very difficult to detect and handle all possible outcomes.

  When JE detects the interrupt, it will mark the environment invalid and will throw a `ThreadInterruptedException`. This tells you that you must close the environment and re-open it before using it again. This is necessary, because if JE didn't throw `ThreadInterruptedException`, it is very likely that you would get some other exception that is less meaningful, or simply see corrupted data.

  Instead, applications should use other mechanisms like `Object.notify` and `wait` to coordinate threads. For example, use a `keepRunning` variable of some kind in each thread. Check this variable in your threads, and return from the thread when it is false. Set it to false when you want to stop the thread. If this thread is waiting to be woken up to do another unit of work, use `Object.notify` to wake it up. This is the recommended technique.

  However, if the use of `Thread.interrupt` is unavoidable, be sure to use it only when shutting down the environment. In this situation, the `ThreadInterruptedException` should be expected. Note that by shutting down the environment abnormally, recovery time will be longer when the environment is subsequently opened, because a final checkpoint was not performed.

  Existing `Environment` handles are invalidated as a result of this exception.

  Since:
    4.0
  See Also:
    Serialized Form

- - ### Method Summary

    - ### Methods inherited from class com.sleepycat.je.EnvironmentFailureException

      `getMessage`

    - ### Methods inherited from class java.lang.Throwable

      `addSuppressed, fillInStackTrace, getCause, getLocalizedMessage, getStackTrace, getSuppressed, initCause, printStackTrace, printStackTrace, printStackTrace, setStackTrace, toString`

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

Copyright (c) 2004, 2014 Oracle and/or its affiliates. All rights reserved.