Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

Using searchService to search in a separate thread in Jira 8


Hi, community!

We are trying to upgrade to Jira 8 and are having an issue with the searchService functionality. 

We have several scripted listeners that are running in separate threads, but after upgrading to Jira 8, we encountered new exceptions. 

This is the code we use for search:

def searchService = ComponentAccessor.getComponent(SearchService.class)
def queryParser = ComponentAccessor.getComponent(JqlQueryParser)
def query = queryParser.parseQuery(jqlSearch)
def search =, query, PagerFilter.getUnlimitedFilter())
List<Issue> issues = search.results

But the whole block runs in a separate thread (each listener starts with Thread.start function).

Please help me fix this. We can't remove the threading because otherwise, all the listeners run on the UI thread, and the user feels the slowness.



2 answers


I'm gonna answer to myself here, just to help others if and when they have the same problem. This answer actually comes from Adaptavist support team:

It seems like you will need to set up a fresh thread-local context at the start of your threaded code, then tear it down at the end:

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.util.thread.JiraThreadLocalUtil

def jtlu = ComponentAccessor.getComponent(JiraThreadLocalUtil)
try {
    //code code code} finally {

(Obviously the above needs to be wrapped in whatever threading boilerplate you are using. The postCall method requires you to pass in a logger but I believe that the log provided by ScriptRunner in the bindings should suffice.)


Hope this helps! :-)


Thanks for sharing it

I have listener in Jira which have complex code and taking time , so what did, i am creating a new thread so the user can proceed with the issue.


I am facing the same error in logs as mentioned above, here is my code


try {
Thread.start("My-Thread", {

} catch (Exception e) {
logs("Error occurred: ${e.getCause()}")
finally {


In my code i am doing multiple actions like


- Updating custom fields

- Creating issues

- Adding comments


Can you please guide what is 


I did like this way and error gone, is it the right one , are you using on Prodcution?


Thread.start("Thread-Send-Comments-BMC", {
def jtlu
try {

jtlu = ComponentAccessor.getComponent(JiraThreadLocalUtil)
postCommentsToBMC(issue, comments, bmcTicketId, sendCommentsPath)
} catch (Exception e) {
logs("Error occured while sending comments : ${e.getCause()}")
finally {



0 votes

What are the exceptions you're getting?

Hi Matt!

I'm getting the following exception in my code:

2019-11-04 11:02:11,167 Thread-32757 ERROR gordon [com.indigo.InvolvedTeamsListener] Exception for issue SWSHANI-805: java.lang.IllegalStateException: Incorrect usage of JIRA/lucene search API. You can only create/use: ManagedIndexSearcher inside a context (request or Jira-Thread-Local). Check: JiraThreadLocalUtils for details.
2019-11-04 11:02:11,180 Thread-32757 ERROR gordon [com.indigo.InvolvedTeamsListener] com.atlassian.jira.index.ManagedIndexSearcherFactory.createFrom(
sun.reflect.GeneratedMethodAccessor988.invoke(Unknown Source)
com.sun.proxy.$Proxy8.getIssueSearcher(Unknown Source)$ Source)

I basically sais I can't use search functionality inside a separate thread.

Any suggestions? 

Hi @Matt Doar__ LinkedIn , We are also facing the same issue. Any help will be much appreciated. 


Any update on this issue? I have the same requirement.


Ahmed Trabelsi

Suggest an answer

Log in or Sign up to answer
Community showcase
Published in Apps & Integrations

🍻🍂Apptoberfest Update: Upcoming Virtual Events 🎉

Hello Community! I hope you've been enjoying the 🍂Apptoberfestivities🍂 (I know I have!) The event is heating up next week with a series of virtual events that we're calling the 🍻🍂Partner App ...

464 views 5 18
Read article

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you