public class

JiraThreadLocalUtils

extends Object
java.lang.Object
   ↳ com.atlassian.jira.util.thread.JiraThreadLocalUtils

Class Overview

This class has static methods that perform a number of standard operations at the start and end of "runnable code" such as a 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, ProblemDeterminationCallback) in a finally block to guarantee correct behaviour. For example:

 public void run()
 {
     JiraThreadLocalUtils.preCall();
     try
     {
         // do runnable code here
     }
     finally
     {
         JiraThreadLocalUtils.postCall(log, myProblemDeterminationCallback);
     }
 }
 

Summary

Nested Classes
interface JiraThreadLocalUtils.ProblemDeterminationCallback This interface is used as a callback mechanism in the case where "runnable code" has completed and the postCall determines that it did not clean up properly. 
Public Constructors
JiraThreadLocalUtils()
Public Methods
static void postCall(Logger log, JiraThreadLocalUtils.ProblemDeterminationCallback problemDeterminationCallback)
This should be called in a finally block to clear up ThreadLocals once the runnable stuff has been done.
static void preCall()
This should be called before any "runnable code" is called.
[Expand]
Inherited Methods
From class java.lang.Object

Public Constructors

public JiraThreadLocalUtils ()

Public Methods

public static void postCall (Logger log, JiraThreadLocalUtils.ProblemDeterminationCallback problemDeterminationCallback)

This should be called in a finally block to clear up ThreadLocals once the runnable stuff has been done.

Parameters
log the log to write error messages to in casse of any problems
problemDeterminationCallback 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 void preCall ()

This should be called before any "runnable code" is called. This will setup a clean ThreadLocal environment for the runnable code to execute in.