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

How to dispach task off the event thread onto a separate thread pool?

Mathieu Yargeau July 14, 2016

My plugin is now catching the event listener onBuildStatusSet to search for a pull request corresponding to the commit that was just updated (for the build status) and adds a comment in that pull request.

However, it seems to cause issues. After a while, I have errors mentioning RejectedExecutionException.

I searched and found this https://confluence.atlassian.com/bitbucketserverkb/rejectedexecutionexception-779171377.html?utm_medium=logScan&utm_source=STP

 

Seems that to not impact Bitbucket's performances, I have to dispatch my processing to a separate thread. How would I go about doing that?

 

 

public class UpdatePullRequestComments
{
    @EventListener
    public void onBuildStatusSet(BuildStatusSetEvent event)
    {
        TriggerUpdatePR(event.getCommitId(), buildStatus);
    }
}

 

Ideally, I would like to call `TriggerUpdatePR` on a separate thread.

 

EDIT:
I just found java.util.concurrent.ExecutorService

public class UpdatePullRequestComments
{
    @EventListener
    public void onBuildStatusSet(BuildStatusSetEvent event)
    {
        executorService.submit(() -> TriggerUpdatePR(event.getCommitId(), buildStatus));
    }
}

 

Would that do the trick or I will have the same issue?

1 answer

1 accepted

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

2 votes
Answer accepted
Ulrich Kuhnhardt _IzymesDev_
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
July 15, 2016

Executorservice does the job perfectly

Mathieu Yargeau July 15, 2016

Great, I'll deploy that version then.

TAGS
AUG Leaders

Atlassian Community Events