Singleton instances of PySystemState and "__import__" in a Multi-Thread Environment

Rotsen Marcello <[email protected]>
Newsgroups gmane.comp.lang.jython.devel
Message-ID <CAA_mf+WfmK3iNpoR=4m5m9TdsDyEpTZ5dMuczqZED5DxyLKPxg@mail.gmail.com>
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

------------------------------------------------------------------------------
Transform Data into Opportunity.
Accelerate data analysis in your applications with
Intel Data Analytics Acceleration Library.
Click to learn more.
http://pubads.g.doubleclick.net/gampad/clk?id=278785111&iu=/4140

_______________________________________________
Jython-dev mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/jython-dev
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.