access cache in server code

Hi team,
Currently tweaking my server code to have it execute within 20 seconds. Playing with the idea of saving some data in cache rather than a data table. Is this possible in server code? I am getting an error relating to permissions creating a thread:

[ERROR] You have no permission to create thread in CodeRunner secure group

Is this something to do with accessing cache in my custom business logic? Error seems to disappear when I comment out the cache code.
Cheers,
Mitch

Hi Mitchell,

Could you please share your server code project with us by sending it to support@backendless.com? Also comment out code which causes issues

Anton

Thanks Anton, I’ve sent through the project now

Mitchell, you forgot to comment out code which is causing issues. What timer are you working on? You may just tell which class and lines of code to comment out

My apologies Anton. This is happening specifically for the ‘priceGetter’ timer. You will see when the line that saves the cache is commented out there is no error

I should add that this error is not thrown every time I try to save to cache. There are some rare cases where the error is not thrown

Hello,

we have checked your project but it is too big to understand what exactly causes the issue. Please create a minimal project that demonstrates the issue and attach it to this topic.

Hi Sergey,

I have narrowed down the issue. The code in ‘PriceGetterTimer’ retrieves JSON from a several urls and saves responses to cache. The code works up until a point, something like 5-6 calls of the timer, then the error occurs for the line which is calling the JSON parser, eg root = jp.parse(new InputStreamReader((InputStream) request.getContent()));

This is most strange to me, particularly because this exact code has existed in a previous timer with no errors. All I have changed is splitting the code into the new timer ‘PriceGetterTimer’ which takes care of the JSON retrieval and saving.

When I move the code back into my main timer ‘JavaWorkerTimer’ there is no error posted, even through its the exact same code, it doesn’t make sense to me.

Any ideas?

Hard to say what is the reason. Can you use this workaround and split the code?

As a temporary measure I have changed my data flow such that individual devices upload the parsed JSON data to backendless, then it is processed in backendless business logic accordingly.

Do you have any examples of a way to retrieve and parse JSON in backendless business logic (JAVA) that doesn’t use asynchronous/additional thread calls?

Obviously the ideal case is to have backendless handle the data retrieval, rather than rely on user devices to upload it periodically

Unfortunately there are no such examples. You may try org.json library, as far as I know it’s not that hungry for threads. But I would recommend switching to JS business logic to avoid thread manipulation exceptions, parsing JSON objects is pretty simple in JS

Anton

Thanks Anton, I will take a look into it. I have never worked with JS before, is there much of a learning curve compared to Java?