我是靠谱客的博主 稳重宝马,这篇文章主要介绍java使用python库_使用python中的java库(java包的Python包装器),现在分享给大家,希望可以做个参考。

在从Python发送通知之前,您可以使用一个永不结束的线程创建一个类java程序.

这样lib就可以保存在内存中,并可以从Python程序中访问.

这个类可能是这样的(添加你需要的lib import / init):

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();

}

}

你必须启动java程序,使用lib,然后使用die()方法杀死Python中的java程序:

gateway = JavaGateway()

do your stuff here using the lib

tp = gateway.entry_point

tp.die()

最后

以上就是稳重宝马最近收集整理的关于java使用python库_使用python中的java库(java包的Python包装器)的全部内容,更多相关java使用python库_使用python中内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(112)

评论列表共有 0 条评论

立即
投稿
返回
顶部