我试图找到一个不使用叉子的替代 Java Runtime. exec () 。 问题在于我们的 JVM 消耗了大部分的内存和运行时间。 exec fork on that process 可能引起记忆问题, 即使是在书写和超版的拷贝( 经常在堆叠流中讨论, 见< a href=> https:// stackoverflow. com/ questions/ 287664/java- runtime- getruntime- exec- oproups" > Java Runtime. getRuntime (. exec () 替代品 < /a > )。
在另一个堆积流柱上,提出了使用日本国家航空局的解决办法,但对这一解决办法没有意见,也没有高分:
同样,这里也提出了一个类似的日本皇家陆军解决方案:http://sanjittmohanty.wordpress.com/2011/12/20/overfound-runtime-exec-havoc- with-jna/
我的问题是:是否使用日本国家航空局(JNA)使系统呼叫防止叉子,它是否避免了随后叉子可能造成的内存分配问题?我使用的代码是:
public class TestJNA {
private interface CLibrary extends Library {
CLibrary INSTANCE = (CLibrary) Native.loadLibrary("c", CLibrary.class);
int system(String cmd);
}
private static int exec(String command) {
return CLibrary.INSTANCE.system(command);
}
public static void main(String[] args) {
exec("ls");
}