Additional Java Thread

Hello,

I am currently developing CloudCode with Java and I am reciving the error that I cannot allocate a new thread and the solution for this is buying a function pack from the Backendless Marketplace.
So I found the package in the Marketplace and was curious how many more Java threads I can allocate after buying the package or are there any restrictions after buying it?
Or is there any other solution for this problem as I am currently on the Springboargplan and I don’t want to upgrade to Cloud 9 yet?

Thanks in advance for an answer.

Best regards,
Bernhard

Hi, @Bernhard_Hammer

How many threads do you have for now in your app on the Springboard?

Regards,
Marina

Hi @Marina.Kan

to be honest I am not really sure I am currently using one Eventhandler and one Timer and in each I am making two calls to the Backendless Database. Is it possible that I maybe send you an email with the code and you take a look?

Regards,
Bernhard

@Bernhard_Hammer, as soon as you wrote to us, we checked your case and also experienced the problem of adding a new Java stream. We created a problem ticket - BKNDLSS-23263. Our team is already working on it. I believe that your problem is caused by it. We apologize for the inconvenience. We try to do our best to fix it.

Regards,
Marina

@Marina.Kan, thank you for fixing the problem.

@Marina.Kan I just wanted to ask if you could find the probable cause of the problem or is it a problem from my side?

Hello @Bernhard_Hammer

We will be happy to assist you. I need to ask you a few more questions to better answer your question.

  1. What is your applicationId?
  2. Have you switched from springboard to cloud9?
  3. When deploying what code did you receive an error?
  4. Are you still facing this problem?

ApplicationId: 53F60FB5-E0AF-457D-FF50-ED080AC38500
No I haven’t as I am just in the development and I don’t really want to change to the Cloud 9 if it isn’t necessary. I am receiving the error when I am deploying an EventHandler and a Timer and I am still facing this problem.

HI @Bernhard_Hammer

We have fixed the problem on our side. The issue cannot be reproduced now.
Can you please provide the stacktrace for your error and your EventHandler and Timer classes with the logic. So we can inspect if something is wrong from your side.

Best Regards,
Maksym

Hi @Maksym_Khobotin2

this is the stacktrace of the error: 09:59:33 | com.xperience.timers.PastXperiencesTimer | ERROR | Cannot allocate new thread. You can remove this limitation by purchasing a function pack in Backendless Marketplace.

Can I also send you the code of the EventHandler and Timer per email as I don’t want to share the code publicly?

Best Regards,
Bernhard

Hi, @Bernhard_Hammer

You can send your code me in a private message or per email marina.rudenko@backendlessmail.com

Regards,
Marina

@Bernhard_Hammer, I have checked your project in my application ( which is on the Springboard plan too as you have) and it did not cause any errors while debugging or deploying it. Could you check it now? As I see in your application you have only one deployed JAVA service. So, it has to work. If you do not mind, can we try to deploy it in your app?

Regards,
Marina

@Marina.Kan yeah please deploy it.

I just saw when running the CodeRunner that I get this warning:
WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by com.backendless.coderunner.runtime.security.CodeRunnerSecurityManager (file:/C:/Users/hamme/Desktop/Masterordner/Xperience/CloudCode/bin/CodeRunner.jar) to field java.lang.ThreadGroup.nUnstarted
Threads
WARNING: Please consider reporting this to the maintainers of com.backendless.coderunner.runtime.security.CodeRunnerSecurityManager
WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations
WARNING: All illegal access operations will be denied in a future release

Could this might be a problem?

@Bernhard_Hammer

We will investigate this issue. The internal ticket BKNDLSS-23406 is created.

Regards,
Inna

Hello @Bernhard_Hammer

I made a fix, checked the work of your handler and timer, now everything is working as it should.
Please check if everything works for you and let us know.

Also, you do not need to use Backendless.initApp in handlers and timers, you can remove this call from your handler and your timer.

Thank you for contacting us. Please let us know if you run into any other issues, we’re here to make sure you have a fantastic experience with Backendless.

Thanks for the tip. I removed the Backendless.initApp

Can you run the timer without getting any error? I still can’t download my objects from the database I am getting the error: “Cannot allocate new thread. You can remove this limitation by purchasing a function pack in Backendless Marketplace”.

Hello @Bernhard_Hammer.

We will look at this problem in more detail and report the result.

Regards, Nikita.

1 Like

Hello @Bernhard_Hammer

Try do not use Async API in Timer. Async API causes a new thread to be created.

Blocking and Non-blocking APIs

For example replace in your Timer:

// ***********************************************************
// Asynchronous API:
// ***********************************************************
Backendless.Data.of( E.class ).find( queryBuilder, new AsyncCallback<List<E>> responder);

to

// ***********************************************************
// Synchronous API:
// ***********************************************************
Backendless.Data.of( E.class ).find( queryBuilder );

and

// non-blocking method
unitOfWork.execute( new AsyncCallback<UnitOfWorkResult>responder );

to

// blocking method
UnitOfWorkResult result = unitOfWorkInstance.execute();

Please make changes in your code, test it, and let me know if everything worked out for you.

Please let us know if you run into any other issues, we’re here to make sure you have a fantastic experience with Backendless.

1 Like

Thank you for the solution it is working now