【问题标题】:Multiple Jython environments in single JVM单个 JVM 中的多个 Jython 环境
【发布时间】:2013-01-29 12:27:03
【问题描述】:

是否可以在一个 JVM 下运行多个具有不同系统设置(即库导入路径)的 Jython 环境。

如果可能,请建议如何正确完成。

从技术上讲,没有什么能阻止我多次执行PythonInterpreter interpreter = new PythonInterpreter();。但我想确保里面没有单身人士。

【问题讨论】:

    标签: java jython jython-2.5


    【解决方案1】:

    查看源代码后,似乎 PySystemState 是单例

    Source code

    public class PySystemState extends PyObject implements ClassDictInit {
    ...
        private static boolean initialized = false;
    ...
    

    Source code

    public static synchronized PySystemState doInitialize(Properties preProperties,
                                                     Properties postProperties,
                                                     String[] argv,
                                                     ClassLoader classLoader,
                                                     ExtensiblePyObjectAdapter adapter) {
            if (initialized) {
                return Py.defaultSystemState;
            }
            initialized = true;
    ...
    

    这意味着 PySysStatus 属性只设置一次,下次调用获取 PySysState 将返回相同的 Jython 环境。

    仍然可以使用自定义 ClassLoader 在不同的上下文中初始化不同的 PySysState,但对于我手头的任务来说,这不是必需的。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2019-12-28
      • 1970-01-01
      • 1970-01-01
      • 2015-03-04
      • 1970-01-01
      • 1970-01-01
      • 2012-10-04
      相关资源
      最近更新 更多