Package org.apache.derby.iapi.util
Class InterruptStatus
java.lang.Object
org.apache.derby.iapi.util.InterruptStatus
Static methods to save and retrieve information about a (session) thread's
interrupt status flag. If during operation we notice an interrupt, Derby will
either:
- immediately throw an exception to cut execution short, also resurrecting the thread's interrupted status flag. This does not require use of this class.
- just note the fact using this class (
noteAndClearInterrupt
, or (setInterrupted
)), and retry whatever got interrupted, continuing execution. To achieve this, Derby will always temporarily clear the interrupted status flag. Later, depending on the type of SQL statement, we may wish to interrupt execution by throwing an SQLException at a safe place, say, after a statement in a batch is complete (throwIf
), or just let the execution run to completion, and then just prior to returning to the appliction, the thread's interrupted status flag will resurrected (restoreIntrFlagIfSeen
)
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final ThreadLocal
<Exception> Use thread local variable to store interrupt status flag *only* if we don't have lcc, e.g. during database creation, shutdown etc.static final int
static final int
Constants used by code that retries file operations after seeing the NIO file channel closed due to interrupts. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate static Context
getContextOrNull
(String contextID) Privileged lookup of a Context.static boolean
noteAndClearInterrupt
(String s, int threadsInPageIO, int hashCode) Checks if the thread has been interrupted in NIO, presumably because we saw an exception indicating this.static void
Check if the we ever noticed and reset the thread's interrupt status flag to allow safe operation during execution.static void
Same purpose asrestoreIntrFlagIfSeen()
.static void
Use when lcc is dying to save info in thread local instead.static void
Make a note that this thread saw an interrupt.static void
Check if the we ever noticed and reset the thread's interrupt status flag to allow safe operation during execution, or if the interrupt status flag is set now.
-
Field Details
-
MAX_INTERRUPT_RETRIES
public static final int MAX_INTERRUPT_RETRIESConstants used by code that retries file operations after seeing the NIO file channel closed due to interrupts.- See Also:
-
INTERRUPT_RETRY_SLEEP
public static final int INTERRUPT_RETRY_SLEEP- See Also:
-
exception
Use thread local variable to store interrupt status flag *only* if we don't have lcc, e.g. during database creation, shutdown etc.
-
-
Constructor Details
-
InterruptStatus
public InterruptStatus()
-
-
Method Details
-
setInterrupted
public static void setInterrupted()Make a note that this thread saw an interrupt. Thread's intr status flag is presumably off already, but we reset it here also. Use lcc if available, else thread local variable. -
saveInfoFromLcc
Use when lcc is dying to save info in thread local instead. Useful under shutdown. -
noteAndClearInterrupt
Checks if the thread has been interrupted in NIO, presumably because we saw an exception indicating this. Make a note of this and clear the thread's interrupt status flag (NIO doesn't clear it when throwing) so we can retry whatever we are doing. It will be set back ON before control is transferred back to the application, cf.restoreIntrFlagIfSeen
. The note that we saw an interrupt is stored in the lcc if available, if not, in thread localexception
.- Parameters:
s
- (debug info) whencethreadsInPageIO
- (debug info) number of threads inside the NIO code concurrentlyhashCode
- (debug info) container id- Returns:
- true if the thread's interrupt status flag was set
-
restoreIntrFlagIfSeen
public static void restoreIntrFlagIfSeen()Check if the we ever noticed and reset the thread's interrupt status flag to allow safe operation during execution. Called from JDBC API methods before returning control to user application. Typically, this happens just prior to return in methods that catchThrowable
and invokehandleException
(directly or indirectly) on it, e.g.: InterruptStatus.restoreIntrFlagIfSeen(); return ...; } catch (Throwable t) { throw handleException(t); }
handleException
does its own calls torestoreIntrFlagIfSeen
. IfsetupContextStack
has been called consider using the overloaded variant ofrestoreIntrFlagIfSeen
with an lcc argument. If an interrupt status flag was seen, we set it back on here. -
restoreIntrFlagIfSeen
Same purpose asrestoreIntrFlagIfSeen()
. This variant presumes we are sure we have alcc != null
, i.e.setupContextStack
has been called and not yet restored. Note that we cannot merge this code withrestoreContextStack
, since that is typically called in afinally
block, at which point in time, thelcc
may be gone due to errors of severitySESSION_SEVERITY
orDATABASE_SEVERITY
. If nolcc
is available, use the zero-arg variant. We only need this variant for performance reasons.- Parameters:
lcc
- the language connection context for this session
-
throwIf
Check if the we ever noticed and reset the thread's interrupt status flag to allow safe operation during execution, or if the interrupt status flag is set now. Called when operations want to be prematurely terminated due to interrupt. If an interrupt status flag was seen, but temporarily switched off, we set it back ON here.- Parameters:
lcc
- the language connection context for this session- Throws:
StandardException
- (session level SQLState.CONN_INTERRUPT) if interrupt seen
-
getContextOrNull
Privileged lookup of a Context. Must be private so that user code can't call this entry point.
-