擅长:python、mysql、java
<p>在Python发出通知之前,您可以使一个单类java程序的线程永远不会结束。在</p>
<p>这样,lib就会保存在内存中,并且可以从Python程序访问。在</p>
<p>此类可以如下所示(添加所需的lib import/init):</p>
<pre><code>public class TestPy {
private Thread thread;
public void die() {
synchronized (thread) {
thread.interrupt();
}
}
public TestPy() {
thread = new Thread(){
public void run() {
try {
while (!Thread.interrupted()) {
Thread.sleep(500);
}
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
}
}
};
thread.start();
}
public static void main(String[] args) {
TestPy tp = new TestPy();
GatewayServer server = new GatewayServer(tp);
server.start();
}
}
</code></pre>
<p>您必须启动java程序,使用lib,然后使用die()方法在Python中终止java程序:</p>
^{pr2}$