OpenWGA 7.7 - TMLScript reference

WGA
Method :

synchronizedFunction(func [, syncObj])

On object WGA
Usage Creates a synchronized version of a JavaScript function
Description This function makes Java synchronisation functionality available to TMLScript. It can produce synchronized functions that are automatically prevented from multiple parallel execution. Use this to protected resources from multiple parallel modification or usage.

The result of this function is a synchronized wrapper around the parameter function which itself should be used for function calls rather than the original function.

Normally synchronized functions created by this function can only be executed once at a time. When multiple calls to synchronized functions appear at the same time then the first call is executed while all other calls wait for this call to finish. After that it is determined which next single call may continue while further calls continue their wait until its their turn.

Optionally you can specify a "synchronization object" as parameter "syncObj". Only synchronized functions with the same synchronization object will block each other on execution. That way you can create functions that are only synchronized to some special other functions, those that share the same sync object. Use arbitrary objects as synchronisation objects. They do not need to have any functional capabilities for this task.

For backward compatibility there still is a global function "synchronizedFunction()" available whose use is discouraged since OpenWGA 5.3.

Parameters func (Function):
A JavaScript function to wrap inside a synchronized function

syncObj (Object, optional):
Synchronization object
Return value A synchronized version of the given function (Function)
Allowed in script types
  • WebTML pages and normal WebTML actions
  • Master actions
  • TMLScript tasks in jobs
  • Content type events
    portletevent
Examples This example defines a trivial JavaScript function that is to be synchronized. It is important that only the synchronized version returned by synchronizedFunction() is to be called, not the previously defined function, to ensure correct synchronization.

function myUnsyncedFunction(param) {
   log.info("This function will only be processed one at a time. The param was: " + param);
}
mySyncedFunction = WGA.synchronizedFunction(myUnsyncedFunction);
mySyncedFunction("The Parameter");