Error: java.util.concurrent.RejectedExecutionException

So, I am trying to optimize my code, but periodically get the error: java.util.concurrent.RejectedExecutionException.

Scenario: I grab a list of spaces using the (GET /wiki/rest/api/space) rest api call. Works fine. However, I don’t get the “Last Modified Date” with this call. So after my json is returned, I am iterating over it for each space and passing the space key into another api call to grab the last modified date using rest api search (GET /wiki/rest/api/search) with my added CQL to get the last modified date for each space.

Problem: The code works and returns all of the dates as expected. I know this because I printout the final json data and I can see the dates that I added from the search call. However, periodically I get some blanks due to the error message listed above. It’s basically saying that too many threads are open and when it hits the limit, (10) threads/pools, it skips and moves on to the next one. If it goes back under the limit, then it will continue until it is completed or until it hits the limit again. If I have (100) spaces, the process accounts for all (100) spaces but will either return all data or whatever it was able to grab.

After much testing, I thought this was an Atlassian error because it comes and goes and I don’t have control over the threads/pools the instance has. However, I starting to think it’s because I may not be shutting things down correctly. Below is some pseudo code of what I am trying to achieve:

  1. In one call, I retrieve all of the spaces in the instance (both global and personal).
  2. I pass the current json into a function and iterate over the json object.
  3. For each space key, I construct CQL to grab the last modified date. For example,

/rest/api/search?sql=space=ABC AND lastModified < now() ORDER BY lastModified DESC
/rest/api/search?sql=space=DEF AND lastModified < now() ORDER BY lastModified DESC

  1. Once this above process is done, I get an updated json object and then I pass it to the function to start drawing the table of all of the data.

I am new to promises but have successfully used them in multiple apps. However, it has only been to grab an initial set of data. I am still getting the initial dataset without any errors, but I think I am going wrong with trying to make another call to get a piece of data to add to the final displayed data.

Goal: To grab all of the spaces and then make an additional call to get each space’s last modified date so when I draw my dataTable the “Last Modified” column is populated.

Any guidance is appreciated it. Thanks in advance.

I’ve tried many different implementations but get the same message, periodically, regardless of the implementation:

Error: {“statusCode”:400,“data”:{“authorized”:false,“valid”:true,“errors”:[],“successful”:false},“message”:“com.atlassian.confluence.api.service.exceptions.BadRequestException: CQL was parsed but the search manager was unable to execute the search. CQL: ‘space=BLANK70 AND lastModified < now() ORDER BY lastModified DESC’. Error message: java.util.concurrent.RejectedExecutionException: Task java.util.concurrent.FutureTask@4fad7c21 rejected from java.util.concurrent.ThreadPoolExecutor@babd223[Running, pool size = 10, active threads = 10, queued tasks = 0, completed tasks = 40378]”}

So quick recap (see details in initial post), I make an api call and get a list of spaces in json. I iterate of the json and pass each space key into a function that makes a call to another api endpoint to each space’s lastModified date and add it to the json. I display the final json in a dataTable.

I am getting sporadic results where I get all of the last modified dates for each space or some subset of the desired results. When I get a subset, I get the error message above for each missing last modified date.

Is it possible to make multiple API calls where I use data from the first call and pass it into the second call without getting the above error at all?

Or should I just stop trying to make the second call and just go with the data that is returned in the first call?

Thanks in advance for any guidance.

I resolved my own issue. Basically, I had my async/await in the wrong place. With this combo in place, I get no errors. If removed, I get the results described previously.