Impact of java.lang.Thread.sleep on other processes


Does java.lang.Thread.sleep block other processes? Is Rhino multi-threaded?

Will a loop with sleep cause other javascript processes to run?

1 Like


There are multiple threads executing simultaneously. Some of these could be executing javascript. A sleep-loop in a piece of javascript will consume a thread until the loop ends.



So if we want to perform other operations while a sleep is in effect, it won’t block?

Does Rhino support promises?



If you block a thread, you’re consuming some but not all of the available resources. This is not recommended (for obvious reasons) but no you won’t totally stop all activity on the machine.

Currently Rhino (and the c3 platform) do not support promises. This is a feature targeted for v8. Most requirements can (and should) be addressed without explicitly sleeping a thread, what are you trying to achieve?



We’re waiting for a map-reduce job to finish. AFAIK the platform doesn’t support callbacks, which would be ideal, so we poll periodically.



the MapReduce Type has a completed() method that you can implement in any type that extends/mixes MapReduce, check out the documentation below, but this should remove the need to constantly ping the platform for the status of the job, and then kick off the next task.

If you want the job to also be able to be executed without kicking off a downstream process for testing purposes, or any other reason, notice that the completed() method takes as an input the MapReduce job instance. On this instance, you can create a field called something like ‘runCompleted’ or ‘chainTasks’ and set it to true/false when the job gets run. Coupling the field you created with a ternary in the completed() method can likely achieve what you’re looking for.



There’s also a newish Workflow type, that we are working on documenting up some examples for future use cases. c3ShowType(Workflow) for more details there, if you’re curious.



I was just going to recommend the Workflow type, its great for coordinating long-running processes that are multi-step



I misspoke. We’re actually waiting on a series of map-reduce jobs to complete, and the completed method for each is already in use. But I’ll go back and see how I can leverage this.




A Workflow can help in this case using the Branching and Conditional steps of a workflow. See the In Depth document for more: