public class JiraThreadLocalUtils extends Object
JiraServiceContainerImpl
or a TaskManagerImpl
. Plugin developers that have previously
used this class directly should change to using JiraThreadLocalUtil
from the API,
so that they can avoid having to depend on jira-core
.
The main purpose of this class is to setup and clear ThreadLocal
variables that can otherwise interfere with the smooth running of JIRA
by leaking resources or polluting the information used by the next request.
You MUST remember to call #postCall(Logger, WarningCallback)
in a
finally
block to guarantee correct behaviour. For example:
public void run()
{
JiraThreadLocalUtils.preCall();
try
{
// do runnable code here
}
finally
{
JiraThreadLocalUtils.postCall(log, myWarningCallback);
}
}
JiraThreadLocalUtil
Constructor and Description |
---|
JiraThreadLocalUtils() |
Modifier and Type | Method and Description |
---|---|
static void |
checkClosed(boolean forceClose)
This can be triggered when we are sure the context should be closed.
|
static boolean |
inContext() |
static void |
postCall() |
static void |
postCall(org.apache.log4j.Logger log,
JiraThreadLocalUtil.WarningCallback warningCallback)
This should be called in a
finally block to clear up ThreadLocal s
once the runnable stuff has been done. |
static void |
preCall()
This should be called before any "runnable code" is called.
|
static <T> Callable<T> |
wrap(Callable<T> callable)
Wraps a
Callable in a "before call" to preCall() and "after call" to postCall()
which handles managing Jira thread locals. |
static Runnable |
wrap(Runnable runnable)
Wraps a
Runnable in a "before call" to preCall() and "after call" to postCall()
which handles managing Jira thread locals. |
public static void preCall()
ThreadLocal
environment for the runnable
code to execute in.public static boolean inContext()
public static void postCall()
public static void checkClosed(boolean forceClose)
forceClose
is true.
This means something went wrong (more preCall()
then postCall()
on the thread stack and we want
to make sure the thread is clean.
Note: only call this if you just did a postCall()
and you can not be part of an outer contextforceClose
- when true force close the contextpublic static Runnable wrap(Runnable runnable)
Runnable
in a "before call" to preCall()
and "after call" to postCall()
which handles managing Jira thread locals.public static void postCall(@Nonnull org.apache.log4j.Logger log, @Nullable JiraThreadLocalUtil.WarningCallback warningCallback)
finally
block to clear up ThreadLocal
s
once the runnable stuff has been done.log
- the log to write error messages to in casse 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 be null
, in which case those problems are logged as errors.public static <T> Callable<T> wrap(Callable<T> callable)
Callable
in a "before call" to preCall()
and "after call" to postCall()
which handles managing Jira thread locals.Copyright © 2002-2019 Atlassian. All Rights Reserved.