Using locks in Jython scripts

Are there any sharp edges and warnings when using a ReentrantLock from java.util.concurrent.locks in a script module? Is there advantages to just using import threading with a threading.RLock?

The use case is around locking an object on the globals map (in system.util.globals), but it may be accessed from perspective script transforms, gateway timer scripts, message handlers, etc.

Any wisdom is appreciated!

The implementation of threading.RLock is a java ReentrantLock under the hood. The jython class is a context manager and can be used with the with statement.

Dabbling in system.util.globals requires some care--especially to not accidentally include any custom code in stored objects. Since you tagged this topic as v8.1, you should also be aware of this issue: