From: Ingo A. <de...@sy...> - 2007-07-08 22:32:18
|
Hi, I'm new to Jython and I want to use Jython to script some actions in a multi threaded application. The requirements are: 1. thread safety 2. performance My idea of using Jython is the following: a) Call: PySystemState.initialize(); once at system startup. b) Compile the scripts with String script = ... StringBufferInputStream is = new StringBufferInputStream(script); PyObject pyObject = Py.compile(is, "script.py", "exec"); when the script has changed and save the pyObject in a cache. c) Execute the script (executions happen in more than one thread in parallel): doRequest(String param) { PyObject pyObject = ... // get pyObject from cache PythonInterpreter pi = new PythonInterpreter(); pi.set("param", param); pi.exec(pyObject); String s = (String) pi.get("result", String.class); } There are not many and no big scripts. My questions: - Is this a right way to do it? - Is this the best way to do it? Ingo |