Skip to main content
14-Alexandrite
August 31, 2018
Solved

Can pause() function in snippets be used to put delay in service?

  • August 31, 2018
  • 2 replies
  • 6274 views

var milliseconds = pause();

 

Infinite for loop is causing problem in runtime. Can pause() function be used instead of infinite loop?

Best answer by zyuan1

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.

2 replies

zyuan15-Regular MemberAnswer
5-Regular Member
September 3, 2018

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.

1-Visitor
September 3, 2018

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.

 

14-Alexandrite
October 19, 2018

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.

5-Regular Member
October 25, 2018

Hi @Yedukrishnan

 

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