Skip to Content
Author's profile photo Kai Ullrich

2 quick remarks about delayed tasks

I had already talked about the Sequence of event tasks in the last post. Now when reading again I was thinking about delaying tasks. You probably know the “delay before start” setting in provisioning tasks.


When you use it and the task is called it is scheduled with a delayed execution time as one can easily see when looking into the table mxp_provision:


The drawback here is that often customers want the delay configurable. And you want configurations to be done in one place, e.g. as global constants and not in some place deep in the workflow tree in the Identity Center console. My point is that it would be nice if such a delay could be configurable as global constant. And when reading the above post an idea crossed my mind how this can be done and I wanted to share this with you here. Let’s have a look at the following script:


var delay_in_seconds = Par.get ("DELAYINSECONDS");
// Javascript is not type safe: So first
// convert this into a "real" integer
delay_in_seconds = parseInt (delay_in_seconds);

// Thread.sleep needs the delay in milliseconds
var delay_in_milliseconds = delay_in_seconds * 1000;

// Wait
Thread.sleep (delay_in_milliseconds);

Util_LogValue ("Waited " + delay_in_seconds + " seconds.");

So what we simply do is delegate the waiting to the work process and use a Java class for it. The task that uses it is here


and now we can use a global constant to provide the delay as a function argument.

The drawback here is that we block the entire work process for 20 seconds in this example, so if you intend to wait for a long time (e.g. if you’re having a grace period before deleting an entry) then this is perhaps not the best way. Depending on the load of your system you may end up with dozens or even hundreds of waiting work processes.

2 words about calling Java from Javascript: The importClass statement imports a class and then you can use it. The following works perfectly fine, for instance:

importClass (java.util.Vector);

var v = new Vector ();
v.add ("a first element");
v.add ("another element");

for (var jj=0; jj

Last but not least one tricky thing: If you’re writing your own class which is not in the java package then you need to add a “Packages” in front of the package name:


var cc = new CleverClass ();
cc.doSomething ();

Assigned Tags

      You must be Logged on to comment or reply to a post.
      Author's profile photo Former Member
      Former Member

      thanks again for your blog.

      My questions are
      1) What will happen if server is re-started after 'Thread.sleep' invocation?
      2) what will happen if parseInt(delay_in_seconds) fails (administrator entered not-number in DELAYINSECONDS)? Is there any way to re-run task after error is fixed?

      Documentation says nothing about such problems (at least I can't find it)

      Author's profile photo Kai Ullrich
      Kai Ullrich
      Blog Post Author
      Hi Ivan,

      with "server" you mean the physical machine? I guess in that case the work process is simply stopped and the job removed from the queue. More details are probably indeterministic but this is nothing IdM specific. If you stop a process in the middle of its work then sometimes strange things happen.
      Regarding the second question: If parseInt fails then the script fails. In real life you would make sure by some plausi check or default mechanism you provide a number to the java function. The code you see in the post is just a very simple example.