views:

643

answers:

4

Currently I use 'ln' command via Runtime.exec(). It works fine. The only problem is that in order to do this fork, we need twice the heap space of the application. My app is a 64 bit app with heap size around 10Gigs and thus its runs out of swap space. I couldn't find any configuration that could fix this.

I also want not to use JNI for the same. Also I had heard somewhere that this facility will soon be provided in java 7.

+2  A: 

you could try JNA in place of JNI (JNA has some clear advantages over JNI); yes, check the JSR 203

dfa
A: 

You could use Windows instead of UNIX? ;) I believe JDK7 will be using a call similar to CreateProcess instead of fork where available.

A more practical solution would be to create a new child process soon after starting. If you are using a 10g heap, another small Java process probably wont be so bad. Get that process (via use of streams) to exec.

Tom Hawtin - tackline
+2  A: 

Perhaps this site will be of help: http://java.sun.com/docs/books/tutorial/essential/io/links.html

With kind regards,

Jeroen

Jeroen
Got all excited about that JavaDoc, until I saw "@since 1.7"
Thilo
+1  A: 

This is very easy with JNA:

public interface CLibrary extends Library {
    CLibrary INSTANCE = (CLibrary)
        Native.loadLibrary((Platform.isWindows() ? "msvcrt" : "c"),
                           CLibrary.class);
    int link(String fromFile, String toFile);
}

public static void main(String[] args) {
    CLibrary.INSTANCE.link(args[0], args[1]);
}

Compile and run!

bajafresh4life