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

#1

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

#2

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.

0 Likes

#3

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

Does Rhino support promises?

0 Likes

#4

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?

0 Likes

#5

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.

0 Likes

#6

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.

0 Likes

#7

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.

0 Likes

#8

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

0 Likes

#9

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.

Thanks.

0 Likes

#10

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

0 Likes