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).
Merge pull request #55 from markdingram/master

Avoid a possible threading issue when multiple ScriptFactory created simultaneously