Avoid a possible threading issue when multiple ScriptFactory created simultaneously

Without the introduced synchronisation it is likely to see the DuplicateRealmException
in multithreaded use (e.g. parallel maven build).