jpythonµ÷ÓÃjavaÀàµÄÄ£°å
ʹÓÃJPypeÄ£¿éÈÃPythonµ÷ÓÃJAVAµÄÀà
Python idea! 2009-03-24 19:44 ÔĶÁ267 ÆÀÂÛ0
×ֺţº ´ó´ó ÖÐÖРСС
¿´¿´Àý×Ó¾ÍÖªµÀÀ²£¬ÕæÊÇΪPython£¨²»ÊÇJython£¬¶øÊÇCPython£©ÌṩÁËÇ¿´óÁ¦Á¿£¡
Ê×ÏÈÔÚjavaϽ¨Á¢Ò»¸öÔÙÒ²¼òµ¥²»¹ýµÄ°ü£º
package org.wg3i.test;
class Test {
private String msg;
public Test() {
}
public void speak(String msg) {
System.out.println(msg);
}
public void setString(String s) {
msg = s;
}
public String getString() {
return msg;
}
}
ÔÚPythonÏÂʹÓÃJPypeÄ£¿éÀ´µ÷ÓÃÎÒÃǸոÕÉú³ÉµÄjava°ü£º
import jpype
import os.path
jarpath = os.path.join(os.path.abspath('.'), 'build/jar')
jpype.startJVM(jpype.getDefaultJVMPath(), "-Djava.ext.dirs=%s" % jarpath)
Test = jpype.JClass('org.wg3i.test.Test') # È¡µÃ°üorg.wg3i.testÖеÄÀàTest
t = Test() # ´´½¨TestʵÀý
t.speak("This is a test message") # ³¢ÊÔµ÷ÓÃÀàµÄÒ»¸ö·½·¨
t.setString("Hello, World") #¸ø¶¨String
s = t.getString() # »ñÈ¡String
print s
jpype.shutdownJVM()
ÏÂÃæÀ´½éÉÜÏÂÈçºÎµ÷Óðü¶ø²»ÊǾßÌåµÄÒ»¸öÀࣺ
import jpype
import os.path
classpath = os.path.join(os.path.abspath('.'), 'build/classes')
jpype.startJVM(jpype.getDefaultJVMPath(), "-Djava.class.path=%s" % classpath)
testPkg = jpype.JPackage('org').wg3i.test # È¡µÃ°ü
Test = testPkg.Test # È¡µÃÀà
t = Test() # ´´½¨TestʵÀý
t.speak("This is a test message") # ³¢ÊÔµ÷ÓÃÀàµÄÒ»¸ö·½·¨
t.setString("Hello, World") &nbs
Ïà¹ØÎĵµ£º
/**
* @param args
*/
public static void main(String[] args) {
long time1 = System.currentTimeMillis();
long time2 = System.currentTimeMillis();
while (true) {
while ((time1 - time2) < 30)
& ......
1.//propertyÎļþµÄ¶ÁÈ¡
//com.test.messageÎļþ
package com.test;
import java.util.MissingResourceException;
import java.util.ResourceBundle;
public class Test_Messages {
private static final String BUNDLE_NAME = "com.test.messages";
private static final ResourceBundle RESOURCE_BUNDLE = Reso ......
ÔÚJAVAÖУ¬ÓÐÁù¸ö²»Í¬µÄµØ·½¿ÉÒÔ´æ´¢Êý¾Ý£º
1. ¼Ä´æÆ÷£¨register£©¡£ÕâÊÇ×î¿ìµÄ´æ´¢Çø£¬ÒòΪËüλÓÚ²»Í¬ÓÚÆäËû´æ´¢ÇøµÄµØ·½——´¦ÀíÆ÷ÄÚ²¿¡£µ«ÊǼĴæÆ÷µÄÊýÁ¿¼«ÆäÓÐÏÞ£¬ËùÒԼĴæÆ÷ÓɱàÒëÆ÷¸ù¾ÝÐèÇó½øÐзÖÅä¡£Äã²»ÄÜÖ±½Ó¿ØÖÆ £¬Ò²²»ÄÜÔÚ³ÌÐòÖиоõµ½¼Ä´æÆ÷´æÔÚµÄÈκμ£Ïó¡£
2. ¶ÑÕ»£¨stack£©¡£Î»ÓÚͨÓÃRAMÖУ¬µ ......
¹ØÓÚJavaÒç³ö·ÖÀ࣬ÎÒ¾³£Åöµ½µÄÊÇÁ½ÀࣺһÀàÊÇjava.lang.OutOfMemoryError: Java heap space£¬Ò»ÀàÊÇjava.lang.OutOfMemoryError: PermGen space¡£
ÔÚÕâÁ½ÀàÖУ¬Ç°ÕßÅö¼ûµÄ´ÎÊý±È½ÏƵ·±¡£ÒòΪµ¼ÖÂJava heap spaceµÄÇé¿ö£¬ÓÐʱºò²¢²»ÊÇÄÚ´æ²»¹»£¬ËüÒ²»áÅ×´Ë´íÎóÐÅÏ¢¡£ÀýÈçÎÒ¾ÍÅöµ½¹ýÕâÑùµÄÇé¿ö£¬ÎÒµ±Ê±Í¨¹ýGCÈÕÖ¾·¢ÏÖ£¬ÄÚ´ ......