public class InterruptStatus
extends java.lang.Object
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
)
Modifier and Type | Field and Description |
---|---|
private static java.lang.ThreadLocal<java.lang.Exception> |
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 int |
INTERRUPT_RETRY_SLEEP |
static int |
MAX_INTERRUPT_RETRIES
Constants used by code that retries file operations after seeing the
NIO file channel closed due to interrupts.
|
Constructor and Description |
---|
InterruptStatus() |
Modifier and Type | Method and Description |
---|---|
private static Context |
getContextOrNull(java.lang.String contextID)
Privileged lookup of a Context.
|
static boolean |
noteAndClearInterrupt(java.lang.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 |
restoreIntrFlagIfSeen()
Check if the we ever noticed and reset the thread's interrupt status
flag to allow safe operation during execution.
|
static void |
restoreIntrFlagIfSeen(LanguageConnectionContext lcc)
Same purpose as
restoreIntrFlagIfSeen() . |
static void |
saveInfoFromLcc(LanguageConnectionContext lcc)
Use when lcc is dying to save info in thread local instead.
|
static void |
setInterrupted()
Make a note that this thread saw an interrupt.
|
static void |
throwIf(LanguageConnectionContext lcc)
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.
|
public static final int MAX_INTERRUPT_RETRIES
public static final int INTERRUPT_RETRY_SLEEP
private static final java.lang.ThreadLocal<java.lang.Exception> exception
public static void setInterrupted()
public static void saveInfoFromLcc(LanguageConnectionContext lcc)
public static boolean noteAndClearInterrupt(java.lang.String s, int threadsInPageIO, int hashCode)
restoreIntrFlagIfSeen
.
The note that we saw an interrupt is stored in the lcc if available, if
not, in thread local exception
.s
- (debug info) whencethreadsInPageIO
- (debug info) number of threads inside the NIO
code concurrentlyhashCode
- (debug info) container idpublic static void restoreIntrFlagIfSeen()
Throwable
and
invoke
handleException
(directly or indirectly) on it, e.g.
: InterruptStatus.restoreIntrFlagIfSeen(); return ...; } catch (Throwable t) { throw handleException(t); }
handleException
does its own calls to restoreIntrFlagIfSeen
. If setupContextStack
has been called
consider using the overloaded variant of restoreIntrFlagIfSeen
with an lcc argument.
If an interrupt status flag was seen, we set it back on here.public static void restoreIntrFlagIfSeen(LanguageConnectionContext lcc)
restoreIntrFlagIfSeen()
. This variant presumes
we are sure we have a lcc != null
, i.e. setupContextStack
has been called and not yet restored. Note that we
cannot merge this code with restoreContextStack
, since that is
typically called in a finally
block, at which point in time, the
lcc
may be gone due to errors of severity SESSION_SEVERITY
or DATABASE_SEVERITY
.
If no lcc
is available, use the zero-arg variant. We only need
this variant for performance reasons.lcc
- the language connection context for this sessionpublic static void throwIf(LanguageConnectionContext lcc) throws StandardException
lcc
- the language connection context for this sessionStandardException
- (session level SQLState.CONN_INTERRUPT) if
interrupt seenprivate static Context getContextOrNull(java.lang.String contextID)
Apache Derby V10.13 Internals - Copyright © 2004,2016 The Apache Software Foundation. All Rights Reserved.