problem using Python to increase virtual memory for my java application
I have created a java application in Eclipse which when I increase the VM arguments to -Xmx1024m runs fine. When I try to run the application via the command promt using the following path:
c:\python27\python c:\jars2run\run.py c:\jars2run\myown\ClassTree.jar LiveSimulator2/Live_PairsEngine3 java -Xmx1024m
I get the following error message:
Exception in thread "main" java.lang.OutOfMemoryError: Java heap space
at java.nio.CharBuffer.wrap(Unknown Source)
at java.nio.CharBuffer.wrap(Unknown Source)
at java.lang.StringCoding$StringDecoder.dec… Source)
at java.lang.StringCoding.decode(Unknown Source)
at java.lang.String.<init>(Unknown Source)
at java.lang.String.<init>(Unkn开发者_开发问答own Source)
at com.mysql.jdbc.ResultSet.getStringIntern…
at com.mysql.jdbc.ResultSet.getString(Resul…
at com.mysql.jdbc.ResultSet.getString(Resul…
at LiveSimulator2.Timeseries2.<init>(Timese…
at LiveSimulator2.Live_PairsEngine3.main(Li…
I have found out that I need to add the heap memory requirement in the python script but cannot figure out where in the scipt I have to put the 'java -Xmx1024m' or what ever is needed and therefore the java application still falls over due to lack of memory.
See below for the python script, at the moment the python script just copies the external jars need to run my java application.
import sys
import os
classfile=sys.argv[2];
jar=sys.argv[1];
cp='%s' % jar
FILES=os.listdir('c:/jars2run/3rdparty');
os.chdir('c:/jars2run/3rdparty');
for i in FILES:
if (i.endswith('jar')):
cp='%s;%s' % (cp, i)
cmd='java -classpath "%s" %s' % (cp, classfile)
print('%s' % cmd)
os.system(cmd)
Could someone let me know where the memory increase needs to should go please.
Very grateful for any assistance.
Change this line:
cmd='java -classpath "%s" %s' % (cp, classfile)
to
cmd='java -Xmx1024m -classpath "%s" %s' % (cp, classfile)
BTW: some pointers on Python:
You don't need semicolons on the ends of lines, and you don't need to wrap the
if
condition in parentheses.If your format string is only
"%s"
, then you aren't gaining anything by formatting, just use the string as is.You can append to a string with
+=
.The Python stdlib includes the
glob
module for finding files with shell wildcard patterns.
Using these (and a few others), we can clean up your script:
import sys
import os
import glob
cp = sys.argv[1]
classfile = sys.argv[2]
os.chdir('c:/jars2run/3rdparty')
for f in glob.glob("*.jar"):
cp += ';%s' % f
cmd = 'java -classpath "%s" %s' % (cp, classfile)
print(cmd)
os.system(cmd)
精彩评论