IPC在Java和C ++之间 [英] IPC between Java and C++
问题描述
我的目标是在同一个SQLite数据库中读取两个单独的应用程序(一个在Java和另一个在C + +,在同一台机器上)。 C ++实现已经工作,并具有我需要的所有方法的通信。它使用sqlite3.h库。
第一个理性的做法是在Java应用程序中使用JDBC或SQLite包装器。问题是,我的嵌入式系统(POSIX)具有非常有限的资源,并且需要很长时间来执行一个简单的查询,当我已经包含必要的* .jar。我已经尝试了基督教Werner的Xerial JDBC,sqlite4java,sqljet和Javasqlite包装器/ JDBC驱动程序。
作为解决方法,我已经管理Java应用程序使用系统命令并运行sqlite3命令shell来执行查询并获取答案。我正在寻找一个更时尚和安全的解决方案。
我实际上需要Java应用程序使用C ++的方法。它们只是返回一个字符串,因为方法被实现只返回一个值。经过很多IPC的阅读,我得出结论,我必须使用命名管道。事情是,我必须使用JNI,但我有一个初学者Java级别,到这个时候,JNI对我来说太复杂了。
其实我错了。我不需要使用JNI在Java中使用命名管道。我已经使用基本技术成功地传达了这两个过程。在java中,我刚刚使用FileOutputStream和FileInputStream与命名管道进行通信。
这个链接对我特别有用:
http://carminedimascio.com/2014/01/named- pipes-with-java /
My goal here is to make two separate applications (one in Java and other in C++, both on the same machine) read from the same SQLite database. The C++ implementation already works and has all the methods that I need for that communication. It uses the sqlite3.h libraries.
The first rational thing to do would be to use a JDBC or a SQLite wrapper in the Java application. The problem is that my embedded system (POSIX) has very limited resources and takes very long to execute a simple query when I have included the necessary *.jar into it. I have tried out the Xerial JDBC, sqlite4java, sqljet and the Javasqlite Wrapper/JDBC driver from Christian Werner. The JavaVM just takes too long to load everything and execute it and performance is a critical issue.
As a workaround, I have managed the Java application to use system commands and run the sqlite3 command shell to execute the query and obtain the answer. I am looking for a more "stylish" and secure solution.
I actually need the Java application to use the methods from C++. They just return a string as the methods are implemented to return only one value. After a lot of IPC reading, I have reached the conclusion that I have to use named Pipes. The thing is that I would have to use JNI but I have a beginner Java level and by this time, JNI is just too complex for me. Is JNI an overkill in this case?
What other solution could I implement here?
Actually I was wrong. I don't need to use JNI to use named pipes in Java. I have successfully communicated these two processes using basic techniques. In java I have just used FileOutputStream and FileInputStream to communicate with the named pipes.
This link was specially useful to me:
http://carminedimascio.com/2014/01/named-pipes-with-java/
这篇关于IPC在Java和C ++之间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!