Interface JiraThreadLocalUtil
- All Known Implementing Classes:
JiraThreadLocalUtilImpl
ThreadLocal variables that
can otherwise interfere with the smooth running of JIRA by leaking resources or allowing
stale cached information to survive between requests.
Services that are registered as a JiraService
do not need to use this component, because this cleanup is performed
automatically as part of the service's execution lifecycle. This should also generally
be true of scheduler jobs, such as those executed through SAL's PluginScheduler
or the new SchedulerService, but this was not implemented correctly in JIRA
v6.3.x, so scheduled jobs should also use this component just to be safe.
Additionally, any plugin that creates its own threads for background processing must
use this component to guard its work. Prior to JIRA v6.0, the only way to do this was
to access the jira-core class JiraThreadLocalUtils directly.
You must place the cleanup call to postCall(Logger) or
postCall(Logger, WarningCallback) in a finally block
to guarantee correct behaviour. For example:
public void run()
{
jiraThreadLocalUtil.preCall();
try
{
// do runnable code here
}
finally
{
jiraThreadLocalUtil.postCall(log, myWarningCallback);
}
}
- Since:
- v6.0
-
Nested Class Summary
Nested ClassesModifier and TypeInterfaceDescriptionstatic interfaceThis interface is used as a callback mechanism in the case where "runnable code" has completed and thepostCalldetermines that it did not clean up properly. -
Method Summary
Modifier and TypeMethodDescriptionvoidpostCall()SeepostCall(Logger), but this will use an internal logger.voidpostCall(org.apache.log4j.Logger log) This convenience method is equivalent topostCall(log, null).voidpostCall(org.apache.log4j.Logger log, JiraThreadLocalUtil.WarningCallback warningCallback) This should be called in afinallyblock to clear upThreadLocals once the runnable stuff has been done.voidpostCall(org.slf4j.Logger log) voidpostCall(org.slf4j.Logger log, JiraThreadLocalUtil.WarningCallback warningCallback) voidpreCall()This should be called before any "runnable code" is called.Wraps aRunnablein a "before call" topreCall()and "after call" topostCall()which handles managing Jira thread locals.<T> Callable<T>Wraps aCallablein a "before call" topreCall()and "after call" topostCall()which handles managing Jira thread locals.
-
Method Details
-
wrap
Wraps aRunnablein a "before call" topreCall()and "after call" topostCall()which handles managing Jira thread locals. -
wrap
Wraps aCallablein a "before call" topreCall()and "after call" topostCall()which handles managing Jira thread locals. -
preCall
void preCall()This should be called before any "runnable code" is called. This will setup a cleanThreadLocalenvironment for the runnable code to execute in. -
postCall
void postCall(@Nonnull org.apache.log4j.Logger log) This convenience method is equivalent topostCall(log, null).- Parameters:
log- as forpostCall(Logger, WarningCallback)
-
postCall
void postCall(@Nonnull org.slf4j.Logger log) -
postCall
void postCall()SeepostCall(Logger), but this will use an internal logger. -
postCall
void postCall(@Nonnull org.apache.log4j.Logger log, @Nullable JiraThreadLocalUtil.WarningCallback warningCallback) This should be called in afinallyblock to clear upThreadLocals once the runnable stuff has been done.- Parameters:
log- the log to write error messages to in case of any problemswarningCallback- the callback to invoke in case where problems are detected after the runnable code is done running and its not cleaned up properly. This may benull, in which case those problems are logged as errors.
-
postCall
void postCall(@Nonnull org.slf4j.Logger log, @Nullable JiraThreadLocalUtil.WarningCallback warningCallback)
-