What is a safe way to stop threads in a JE application?
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 which is executing a JE operation, the state of the database 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. If JE can detect the interrupt, it will mark the environment as unusable and will throw a RunRecoveryException. This tells you that you must close the environment and re-open it before using it again. If JE doesn’t throw RunRecoveryException, 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 fro