Error starting the second JVM if it is already running

I am developing client-server software where the server is python developed. I want to call a group of methods from a java program in python. All java methods exist in one jar file. This means that I don't have to load different jars.

I used jpype for this purpose. For every request from a client, I call a python function that looks like this:

def test(self, userName, password):
    Classpath = "/home/DataSource/DMP.jar"
    jpype.startJVM(
        "/usr/local/java/jdk1.7.0_60/jre/lib/amd64/server/libjvm.so",
        "-ea",
        "-  Xmx512m",
        "-Djava.class.path=%s" % Classpath)

    NCh = jpype.JClass("Common.NChainInterface")
    n = NCh(self._DB_ipAddress, self._DB_Port, self._XML_SCHEMA_PATH, self._DSTDir)
    jpype.shutdownJVM()

      

For one function, it works, but for the second call, it fails to start jvm. I have seen many complaints about this, but I could not find any solution for this. I appreciate it if any body can help.

If jpype has problem in multiple start jvm, is there a way to start and stop jvm once? The server is deployed in an Ubuntu VM, but I don't have enough knowledge to write, for example, a script for this purpose. Could you provide a link or example?

+3


source to share


1 answer


Check isJVMStarted()

before startJVM()

.
If the JVM is running it will return True

otherwise False

.

def init_jvm(jvmpath=None):
    if jpype.isJVMStarted():
        return
    jpype.startJVM(jpype.getDefaultJVMPath())

      



For a real example see here .

+5


source







All Articles