#74 Avoid Runtime.getRuntime().exec : JNA ?


This method cause a fork of the JVM and the fork duplicates memory.
So instead of giving 4Go to your application server which use JLine, you have to limit the JVM memory at 2Go.

IMHO the best choice is to use JNA to call system(char *) method.
JNA is a small (1Mo) library which performs "reflexion" on C. Its code use JNI and is compiled on a lot of platform.

Java Code of Runtime.exec substitution

import com.sun.jna.Library;
import com.sun.jna.Native;
import com.sun.jna.Platform;

public class Runtime {

private interface CLibrary extends Library {
CLibrary INSTANCE = (CLibrary) Native.loadLibrary((Platform.isWindows() ? "msvcrt" : "c"), CLibrary.class);
int system(String cmd);

public static int exec(String command) {
return CLibrary.INSTANCE.system(command);



Log in to post a comment.

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:

JavaScript is required for this form.

No, thanks