Community Tip - New to the community? Learn how to post a question and get help from PTC and industry experts! X
var milliseconds = pause();
Infinite for loop is causing problem in runtime. Can pause() function be used instead of infinite loop?
Solved! Go to Solution.
As the description for this service mentions, it "pause for a specific number of milliseconds", so surely it works.
What're you using the infinite loop for, that always cause a problem.
As the description for this service mentions, it "pause for a specific number of milliseconds", so surely it works.
What're you using the infinite loop for, that always cause a problem.
Don't do infinite loops DOT. pause() it's the evil DOT.
When you start a server side service a transaction starts and this transaction doesn't ends until the service ends, then if you have an infinite loop it will never end and you will start having real problems with locks and transactions.
Using pause() it only means you are not dealing well with asynchronism and what it seems to work with pause() for some times other unexpected times won't work, better you get ride of it.
You should use events instead, and act upon a event it's thrown, if you want a recurrent event witch just does one task at a time (one iteration of your infinite loop) use a Timer or Scheduler thing.
If you have time, give a shot to this document: https://community.ptc.com/t5/ThingWorx-Developers/General-Performance-Recommendations-and-some-perks-unofficial/m-p/533554
Regards,
Carles.
Generally speaking you should try to avoid using the pause function whenever possible. It could cause transaction to back up in the JVM possibly cause memory issues. There are a few situations that it can be helpful, but they are use case specific.
NEVER use an infinite loop. This will not release memory and has a high possibility of causing an issue. Timers or schedulers if used correctly (see this link) can be used in place of that structure.
Hope you are doing good. Could you please confirm if the issue has been resolved.
If yes, please mark the answer as accept as solution for the future reference. Thank you in advance.
Regards-Mohit Goel
pause() function is working well.
But, which is the best practice? Infinte loop or pause()