Business Logic - Thread Creation

Hi,

Currently using business logic to get JSON from a third party API and then parse the JSON and act on the data.

I get the following error when I attempt to parse the JSON:

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

I’m curious why this error is thrown, I make no calls to open additional threads. What is different between this error and the similar one:

{"code":0,"message":"Cannot allocate new thread. You can remove this limitation by purchasing a function pack in Backendless Marketplace.","errorData":{}}

This is quite critical business logic so I need to get past this error

Mitch

you have told that:

I am using URLConnection however I'm still getting the above error. What is the difference between my error and the error that George posted?

or you are using some third party sdk wich using URLConnection?

This is how I implement the connection:

URLConnection request = null;
try {
    request = url.openConnection();
} catch (IOException e) {
    e.printStackTrace();
}
try {
    request.connect();
} catch (IOException e) {
    e.printStackTrace();
}

CodeRunner output also says this, if it helps:

java.security.AccessControlException: You have no permission to create thread in CodeRunner secure group.
at com.backendless.coderunner.runtime.security.CodeRunnerSecurityManager.checkAccess(CodeRunnerSecurityManager.java:48)

Sergey,

Thanks for looking into this, I have fixed it myself. For your reference this is the fix:

URLConnection request = null;
try {
    request = url.openConnection();
} catch (IOException e) {
    e.printStackTrace();
}
try {
    request.addRequestProperty("Connection","close");
    request.connect();
} catch (IOException e) {
    e.printStackTrace();
}

Particularly the line

request.addRequestProperty("Connection","close");

Which forces the connection to close each time, otherwise it will try to maintain a persistent connection as per https://docs.oracle.com/javase/7/docs/technotes/guides/net/http-keepalive.html

Cheers,
Mitch

Mitchell, thank you for your response.