cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Community Tip - Did you get called away in the middle of writing a post? Don't worry you can find your unfinished post later in the Drafts section of your profile page. X

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

Yedukrishnan
14-Alexandrite

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

var milliseconds = pause();

 

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

ACCEPTED SOLUTION

Accepted Solutions

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.

View solution in original post

6 REPLIES 6

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.

 

AdamR
14-Alexandrite
(To:Yedukrishnan)

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.

mgoel
17-Peridot
(To:AdamR)

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

Yedukrishnan
14-Alexandrite
(To:AdamR)

pause() function is working well. 

But, which is the best practice? Infinte loop or pause()

@zyuan1

 

Could you please advise on this? Please check otherwise we can reach out to someone else.

Announcements


Top Tags