From: Rotsen M. <rot...@gm...> - 2016-03-10 06:53:05
|
Hi guys, A question about thread-safety: >From a concurrency point of view, is it safe to have singleton instances of PySystemState and "__import__" serving parallel requests coming from different Threads? Something like the code bellow (based on http://www.jython.org/jythonbook/en/1.0/JythonAndJavaIntegration.html#more-efficient-version-of-loosely-coupled-object-factory *)*: import org.python.core.Py; import org.python.core.PyObject; import org.python.core.PySystemState; public class JythonBeanFactory { private static PySystemState state = new PySystemState(); private static PyObject importer = state.getBuiltins().__getitem__(Py.newString("__import__")); public Object createObject(String moduleName, String className) { PyObject module = importer.__call__(Py.newString(moduleName)); PyObject klass = module.__getattr__(className); return klass.__call__().__tojava__(Object.class); } } Thank you, Rotsen |