Important Notice: Our web hosting provider recently started charging us for additional visits, which was unexpected. In response, we're seeking donations. Depending on the situation, we may explore different monetization options for our Community and Expert Contributors. It's crucial to provide more returns for their expertise and offer more Expert Validated Answers or AI Validated Answers. Learn more about our hosting issue here.

What is a safe way to stop threads in a JE application?

application Je safe threads
0
Posted

What is a safe way to stop threads in a JE application?

0

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

Related Questions

What is your question?

*Sadly, we had to bring back ads too. Hopefully more targeted.

Experts123