KB Article #176470

How to Synchronize methods in Groovy Scripting filters

Problem

Groovy scripts calling methods from the main invoke method may run into threading issues if methods aren't synchronized.

Resolution

To avoid concurrent calls, the trick is to put the code in a method, annotated with the @synchronized tag - This method will be locked for thread-2 until thread-1 has finished execution.

e.g.

import groovy.transform.Synchronized;

...

def invoke(msg)
{
myinvoke(msg);
}



@Synchronized
myinvoke(msg)
{
Trace.info("BEG SCRIPTING LANGUAGE");
...
}